您的位置:首页 > 其它

1070. Mooncake (25)解题报告

2016-11-04 10:44 204 查看
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cfloat>
#include <algorithm>
using namespace std;

struct mooncake {
double inventory, price, perprice;
};

bool comp(mooncake m1, mooncake m2);

int main(void) {
mooncake arr[1000];
int i, n;
double inventory, profit, d;
scanf("%d %lf", &n, &d);
for (i = 0; i < n; i++) {
scanf("%lf", &arr[i].inventory);
}
for (i = 0; i < n; i++) {
scanf("%lf", &arr[i].price);
arr[i].perprice = arr[i].price / arr[i].inventory;
}
sort(arr, arr + n, comp);
inventory = profit = 0;
for (i = 0; i < n && inventory < d; i++) {
if (inventory + arr[i].inventory <= d) {
inventory += arr[i].inventory;
profit += arr[i].price;
}
else {
profit += arr[i].perprice * (d - inventory);
inventory = d;
}
}
printf("%.2lf\n", profit);
return 0;
}
bool comp(mooncake m1, mooncake m2) {
return m1.perprice > m2.perprice;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: