2009-01-15 16:39:03來源不明

2008 NPSC B. 下雨天

/***********************************************************/

  1. #include<stdio.h>            
  2. #include<stdlib.h>         
  3. #include<string.h>         
  4. #include<math.h>         
  5. int main()         
  6. {         
  7.  int a,b,c,d,e,s,x,y,z,flag;      
  8.  float temp,max;       
  9.  while(scanf("%d",&x)==1)         
  10.   {         
  11.    for(y=0;y<x;y++)         
  12.     {             
  13.      scanf("%d",&z);         
  14.      for(e=1;e<=z;e++)         
  15.      {         
  16.       scanf("%d %d %d %d %d",&a,&b,&c,&d,&s);         
  17.         temp=sqrt((a-c)*(a-c)+(b-d)*(b-d))*s/abs(a-c);      
  18.        if(e==1) {max=temp;flag=e;}         
  19.        if(temp<max) {max=temp;flag=e;}      
  20.      }          
  21.       printf("%d\n",flag);       
  22.     }         
  23.   }            
  24.  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; 
}