这道题有点小疑问

为什么我用sum_JavaBean+=(double)m / all_evel[j].b*all_evel[j].a;可以达到AC
用sum_JavaBean+=(double)all_evel[j].cost*m;达不到AC 有牛人可以给我解答一下

#include<cstdlib>
#include<cstdio>
#include<string.h>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
struct scale
{
    double a;
    int b;
    double cost;
};
bool complare(scale S1,scale S2)
{

 return S1.cost > S2.cost;

}
int main()
{
    int n,m;
    int i,j;
    int last_level = 0;
    //scale all_evel[10010];
    double sum_JavaBean = 0;
    while(scanf("%d %d",&m,&n)!=EOF)
    {
        sum_JavaBean = 0;
       if(n == -1 && m == -1) 
            break;
       scale *all_evel = new scale[n];
        for(i = 0;i< n ;i++)
        {
            cin>>all_evel[i].a>>all_evel[i].b;
            if(all_evel[i].b == 0)
            {
              all_evel[i].cost = 10000;
            }
            else
                all_evel[i].cost = (float)all_evel[i].a / all_evel[i].b;
        }
        sort(all_evel,all_evel+n,complare);
        for(j=0;j<n;j++)
        {
            if(m>all_evel[j].b)
            {
                sum_JavaBean+=all_evel[j].a;
                m -= all_evel[j].b;
            }
            else 
            {
                sum_JavaBean+=(double)m / all_evel[j].b*all_evel[j].a;
                m = 0;
                break;
                delete []all_evel;
            }
        }
        printf("%.3lf\n",sum_JavaBean);
    }
return 0;
}
posted on 2017-06-06 16:26  HDU李少帅  阅读(150)  评论(0编辑  收藏  举报