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; }
相关文章推荐
- PAT (Advanced Level) 1125. Chain the Ropes (25) 解题报告
- PAT 1025 反转链表 (25) 解题报告
- PAT (Advanced Level) 1006. Sign In and Sign Out (25) 解题报告
- PAT (Advanced Level) 1102. Invert a Binary Tree (25) 解题报告
- PAT (Advanced Level) 1126. Eulerian Path (25) 解题报告
- PAT (Advanced Level) 1007. Maximum Subsequence Sum (25) 解题报告
- 1044. Shopping in Mars (25)解题报告
- 【解题报告】【浙大PAT】1051. Pop Sequence (25)
- 1055. The World's Richest (25)解题报告
- 1044. Shopping in Mars (25)解题报告
- 1056. Mice and Rice (25)解题报告
- 9-25 解题报告
- 1036. Boys vs Girls (25)解题报告
- 1078. Hashing (25)解题报告
- 1105. Spiral Matrix (25)解题报告
- Integer Set Partition (25)解题报告
- 剑指offer解题报告(Java版)——二叉树中和为某一值的路径 25
- 1048. Find Coins (25)解题报告
- 1079. Total Sales of Supply Chain (25)解题报告
- [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总