这道题有点小疑问
为什么我用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;
}
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》