PAT 1070. Mooncake (25) 贪心
2018-01-19 15:24
330 查看
/************************* 题意: 给出每块月饼的质量,和这块月饼的价格 问商家怎么切掉并组合,才能组合出一个最贵的月饼 ************************/ /*********************** 贪心思想 即每次先消耗单位价格最贵的月饼即可。 *************************/ /*********************** 笔记: *********************/ #include<iostream> #include<stdio.h> #include<string> #include<vector> #include<queue> #include<stdlib.h> #include<algorithm> #include<string.h> #include<stack> #include<map> #include<set> #include<unordered_map> using namespace std; #define M 110000 #define INF 0x7fffffff struct Mooncake{ double w; double price; }; Mooncake mooncake[M]; bool cmp(Mooncake a,Mooncake b){ return a.price/a.w > b.price/b.w; } int main(){ int n,i; double d,w,price; cin>>n>>d; for(i=0;i<n;i++){ scanf("%lf", &mooncake[i].w); } for(i=0;i<n;i++){ scanf("%lf", &mooncake[i].price); } sort(mooncake,mooncake+n,cmp); double ans = 0; for(i=0;i<n;i++){ if(mooncake[i].w < d){ d -= mooncake[i].w; ans += mooncake[i].price; } else if(mooncake[i].w >= d){ ans += d * mooncake[i].price / mooncake[i].w; break; } } printf("%.2lf\n",ans); return 0; }
相关文章推荐
- PAT - 甲级 - 1037. Magic Coupon (25)(贪心)
- 1033. To Fill or Not to Fill (25)(加深对贪心的理解!!!)
- Educational Codeforces Round 25 C Multi-judge Solving 贪心
- PAT - 甲级 - 1067. Sort with Swap(0,*) (25)(模拟+贪心)
- 1033. To Fill or Not to Fill (25)【贪心+模拟】——PAT (Advanced Level) Practise
- PAT 1033. To Fill or Not to Fill (25) 加油站贪心问题
- PAT - 甲级 - 1070. Mooncake (25)(贪心)
- PAT 1033. To Fill or Not to Fill (25) 贪心
- PAT (Advanced Level) 1044. Shopping in Mars (25) 找符合要求的连续子数组,贪心
- 【贪心】PAT 1033. To Fill or Not to Fill (25)
- 1067. Sort with Swap(0,*) (25)【贪心】——PAT (Advanced Level) Practise
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
- PAT 1020 完美数列(25)(贪心暴力)
- 1070. Mooncake (25)【贪心】——PAT (Advanced Level) Practise
- 1037. Magic Coupon (25)贪心
- PAT 1055 Mooncake (25)(贪心,最大利润)(待修改)(官网有个测试点通不过,不知到错在哪,下次再改好了)
- Educational Codeforces Round 25 D Suitable Replacement 贪心
- Num 25 : NYOJ0014 会场安排问题 + HDOJ2037:今年暑假不AC [ 贪心 ][ 选择不相交区间 ]
- PAT - 甲级 - 1033. To Fill or Not to Fill (25)(贪心)
- 1033. To Fill or Not to Fill (25) (贪心好题)