这题太奇葩了
刚开始测试点第三个通不过,找了半个小时原因,结果是题干中说了月饼总数是int但是必须用浮点数不然通不过第三个点
#include <cstdio>
#include <algorithm>
using namespace std;
typedef struct node
{
double num;
double tp;
double sp;
}mooncake;
bool cmp(mooncake a,mooncake b)
{
if(a.sp != b.sp)
return a.sp > b.sp;
}
int main()
{
int n;
double m;
double sum = 0;
mooncake moon[1010];
scanf("%d %lf",&n,&m);
for(int i = 0;i<n;i++)
{
scanf("%lf",&moon[i].num);
}
for(int i = 0;i<n;i++)
{
scanf("%lf",&moon[i].tp);
moon[i].sp = moon[i].tp / moon[i].num;
}
sort(moon,moon + n,cmp);
for(int i = 0;i<n;i++)
{
if(moon[i].num <= m)
{
m-=moon[i].num;
sum += moon[i].tp;
}
else
{
sum += moon[i].sp * m;
break;
}
}
printf("%.2lf\n",sum);
return 0;
}