pat_b_1020 月饼
来源:互联网 发布:java xml转json 编辑:程序博客网 时间:2024/04/27 19:26
http://pat.zju.edu.cn/contests/pat-b-practise/1020
分析: 贪心——按单价大者优先;
注意: 月饼库存量为int数据类型时,有一组数据不能通过;改为double,AC
代码:
<span style="font-size:24px;">//月饼#include <iostream>#include <stdio.h>#include <string.h>#include <string>#include <algorithm>using namespace std;const int maxn=1002;struct node{ double num; double price; double v;}a[maxn];int cmp(node x, node y){ return x.v - y.v > 0.000001;}int main(){ freopen("in.txt","r",stdin); int n,w; double ans=0; scanf("%d%d",&n,&w); for(int i=0;i<n;i++) scanf("%lf",&a[i].num); for(int i=0;i<n;i++) scanf("%lf",&a[i].price); for(int i=0;i<n;i++) a[i].v = a[i].price / a[i].num; sort(a,a+n,cmp); for(int i=0;i<n;i++){ if(w < a[i].num) { ans += w*a[i].v; break; } ans += a[i].price; w -= a[i].num; } printf("%.2lf\n",ans); return 0;}</span>
0 0
- pat_b_1020 月饼
- 月饼
- 月饼
- 月饼
- 月饼机小介
- PAT1020. 月饼
- 1020. 月饼
- 1020月饼
- 1020. 月饼
- 1020. 月饼
- PAT1020月饼
- pat1020:月饼
- 1020. 月饼
- PAT 月饼
- 1020 月饼
- 1020 月饼
- 月饼 (25)
- 月饼问题
- flex加载swf文件进行跨域操作时出现异常 安全沙箱冲突
- 钟表的时针分针每天重叠多少次
- UVA10817 状压DP+01背包思想
- 恶意软件正在利用SSL服务器窃取用户个人信息!
- little cmds
- pat_b_1020 月饼
- hdu steps 1.2.3 find your presents(2)
- 搭建 pox、mininet、poxdesk平台
- 关闭页面之前 提示用户(确定跳转,取消停留)----使用window.onbeforeunload
- IT猎头之挖角与反挖角
- Android progressbar
- Extjs中三种不同的数据提交方式
- jsweixinbridge关注
- 5.触摸touch,单点触摸,多点触摸,触摸优先和触摸事件的吞噬