AcWing 1556. 月饼
原题链接
简单
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1100;
struct Cake{
double s; // 总量
double w, avg;
}cake[N];
bool cmp(Cake a,Cake b)
{
return a.avg > b.avg;
}
int main()
{
int n; // 需求req
double req;// 注意需求量一定要为double
cin >> n >> req;
for(int i = 0;i < n;i++) cin >> cake[i].s;
for(int i = 0;i < n;i++){
cin >> cake[i].w;
cake[i].avg = cake[i].w / cake[i].s; // 单价
}
sort(cake,cake+n,cmp);
double sum = 0.0;
for(int i = 0;i < n;i++)
{
if(req >= cake[i].s) sum += cake[i].w, req -= cake[i].s;
else{
sum += cake[i].avg * req;
break;
}
}
printf("%.2lf",sum);
return 0;
}
兄弟有时间填个邀请码hhhhhhhhh(都可以得AC币,邀请码在学生认证那填) 我的邀请码是:GUDFH