标签:ons typedef bool ret using namespace ace struct std
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn = 1000;
typedef struct yuebing {
double cun;
double shouyi;
double danjian;
}yue;
yue arr[maxn];
bool cmp(yue a, yue b) {
return a.danjian>b.danjian;
}
int main()
{
int N, D; double shoushou = 0;
scanf("%d%d", &N, &D);
//输入库存
for (int i = 0; i<N; i++) {
scanf("%lf", &arr[i].cun);
}
//输入收益,并计算单收益
for (int i = 0; i<N; i++) {
scanf("%lf", &arr[i].shouyi);
arr[i].danjian = arr[i].shouyi / arr[i].cun;
}
sort(arr, arr + N, cmp);//根据但收益排序
for (int i = 0; i<N; i++) {
if (arr[i].cun >= D) {
shoushou += arr[i].danjian*D;
break;
}
if (arr[i].cun<D)
shoushou += arr[i].shouyi;
D -= arr[i].cun;
}
printf("%.2f", shoushou);
return 0;
}
标签:ons typedef bool ret using namespace ace struct std
原文地址:https://www.cnblogs.com/hebust/p/9498093.html