user-0 提问: 杭电acm 1009这道题一直WA，数据以及特殊数据测试了一些也没问题，感觉也不是精度缺失的问题，希望各位大侠能帮忙指点下，感谢！

回复:
user: user-0
content: 谢谢 hnwyllmm 羽飞哈。 我后来发现原来一直是代码里面写欠了 这是改后的代码，AC了 #include<stdio.h> int main(){     double m,n;     while(scanf("%lf %lf",&m,&n)!=EOF&&(m!=-1)&&(n!=-1)){           int i,j,t;           double sum=0,a[1000]={0},b[1000]={0};           for(i=0;i<n;i++){               scanf("%lf %lf",&a[i],&b[i]);                        }           for(i=0;i<n-1;i++){               for(j=i;j<n-1;j++){                   if((a[i]/b[i])<(a[j+1]/b[j+1])){                       t=a[i],a[i]=a[j+1],a[j+1]=t;                      t=b[i],b[i]=b[j+1],b[j+1]=t;                   }               }           }           for(i=0;i<n;i++){                   if((m!=0)&&(m<b[i])){                      sum=sum+m*a[i]/b[i];                      break;                   }                                      if(m>b[i]){                      m=m-b[i];                      sum=sum+a[i];                   }                   if(m==b[i+1]){                       sum=sum+a[i+1];                      if(b[i+1]!=0)                      break;                   }           }           printf("%.3lf\n",sum);     } }

user: user-0
content: 另外关于 0 1 123 0 0.000这样特殊例子没有影响的，照样AC，嗯，就这样了

user: user-0
content: 然后还发现，其实代码可以在简点的 之前以为要考虑一些啥啥啥的特殊情况，然后就写了一些不必要的情况，导致了错误率提高唉 简单点的代码： #include<stdio.h> int main(){     int m,t,n;     while(scanf("%d %d",&m,&n)!=EOF&&(m!=-1)&&(n!=-1)){           int i,j;           double sum=0,a[1000]={0},b[1000]={0};           for(i=0;i<n;i++){               scanf("%lf %lf",&a[i],&b[i]);                        }           for(i=0;i<n-1;i++){               for(j=i;j<n-1;j++){                   if((a[i]/b[i])<(a[j+1]/b[j+1])){                       t=a[i],a[i]=a[j+1],a[j+1]=t;                      t=b[i],b[i]=b[j+1],b[j+1]=t;                   }               }           }           for(i=0;i<n;i++){                   if(m<b[i]){                      sum=sum+m*a[i]/b[i];                      break;                   }                                      if(m>=b[i]){                      m=m-b[i];                      sum=sum+a[i];                   } //                  if(m==b[i+1]){                //之前这一段写欠了"+1",致使WA  //                     sum=sum+a[i+1];            //而这一段其实可以去掉  //                     if(b[i+1]!=0)              //个人觉得要熟悉不同类型值之间的赋值  //                     break;                     // //                  }                             //           }           printf("%.3lf\n",sum);     } }

user: user-1
content: 提醒楼主两点：一个是浮点数的等于运算，不能直接用==，一个是浮点数打印最后结果，应该用四舍五入

user: user-1
content: 楼主参考下论坛上的讨论，一些前辈们的经验都在这里： http://acm.hdu.edu.cn/discuss/problem/list.php?problemid=1009

user: user-1
content: 我帮楼主把问题贴出来： FatMouse' Trade  Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.    Input The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.    Output For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.    Sample Input 5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1    Sample Output 13.333 31.500