2008 NPSC B. 下雨天
/***********************************************************/
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<math.h>
- int main()
- {
- int a,b,c,d,e,s,x,y,z,flag;
- float temp,max;
- while(scanf("%d",&x)==1)
- {
- for(y=0;y<x;y++)
- {
- scanf("%d",&z);
- for(e=1;e<=z;e++)
- {
- scanf("%d %d %d %d %d",&a,&b,&c,&d,&s);
- temp=sqrt((a-c)*(a-c)+(b-d)*(b-d))*s/abs(a-c);
- if(e==1) {max=temp;flag=e;}
- if(temp<max) {max=temp;flag=e;}
- }
- printf("%d\n",flag);
- }
- }
- return 0;
- }
/*****************************/
輸入太多,來個優化輸入吧!
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long long int input()
{
char cha;
unsigned long long int x=0;
while(cha=getchar())
if(cha!=' '&&cha!='\n') break;
x=cha-48;
while(cha=getchar())
{
if(cha==' '||cha=='\n') break;
x=x*10+cha-48;
}
return x;
}
int main()
{
int a,b,c,d,e,s,x,y,z,flag;
float temp,max;
while(scanf("%d",&x)==1)
{
for(y=0;y<x;y++)
{
scanf("%d",&z);
for(e=1;e<=z;e++)
{
a=input();b=input();c=input();d=input();s=input();
temp=sqrt((a-c)*(a-c)+(b-d)*(b-d))*s/abs(a-c);
if(e==1) {max=temp;flag=e;}
if(temp<max) {max=temp;flag=e;}
}
printf("%d\n",flag);
}
}
return 0;
}
上一篇:2005 NPSC B. 節約尺