pat 1020. 月饼
来源:互联网 发布:数据归一化方法及公式 编辑:程序博客网 时间:2024/05/10 03:30
原题链接:
思路:根据单价进行贪心,优先选择单价高的。我想吐槽一点:明明说的正整数,但是库存和总量却有浮点数,坑爹的测试点2,大家注意了
#include<bits/stdc++.h>using namespace std;typedef long long ll;//测试的数据就是坑typedef pair<double,double> P;const int maxn=1005;int n,d;P cake[maxn];bool cmp(P p1,P p2){ return p1.second*p2.first>p1.first*p2.second;}void print(){ for(int i=0;i<n;i++){ cout<<cake[i].first<<" "<<cake[i].second<<endl; }}void input(){ cin>>n>>d; for(int i=0;i<n;i++){ cin>>cake[i].first; } for(int i=0;i<n;i++){ cin>>cake[i].second; } sort(cake,cake+n,cmp); //print();}void solve(){ double ans=0; /*if(!d){ cout<<0<<endl; return; }*/ for(int i=0;i<n;i++){ if(d<=cake[i].first){ ans+=cake[i].second*1.0/cake[i].first*d; break; }else{ ans+=cake[i].second; d-=cake[i].first; } } printf("%.2f\n",ans);}int main(){ //freopen("in.txt","r",stdin); input(); solve(); return 0;}
阅读全文
0 0
- PAT 1020. 月饼 (25)
- PAT 1020. 月饼<未完>
- PAT 1020. 月饼
- PAT(B) 1020. 月饼
- PAT 乙级 1020.月饼
- PAT-B 1020. 月饼
- PAT 1020. 月饼 (25)
- PAT-B 1020.月饼
- PAT乙级 1020. 月饼
- pat乙 1020. 月饼
- 1020. 月饼 (25) PAT
- [PAT-乙级]1020.月饼
- pat 1020. 月饼
- PAT --- 1020. 月饼 (25)
- Pat 1020. 月饼 (25)
- PAT(B)1020. 月饼 (25)
- PAT (Basic Level)1020. 月饼
- PAT(乙级)1020. 月饼
- NYOJ 814 又见拦截导弹
- Compile Error出现的原因
- Android触摸屏突然没反应了
- 前端优化系列之DNS预解析
- 【免费开源】Asp.net Core 开发的后台框架(权限介绍)
- pat 1020. 月饼
- Towards End-to-end Text Spotting with Convolutional Recurrent Neural Networks阅读笔记
- PyQt4编程之简短地做出多个选择框
- 刷题——Wooden Sticks POJ
- 页面布局思路
- 面试遇见的算法题,进行一下系统总结学习
- ACM训练日记—8月18日
- GJJ来签到
- 01.Lua笔记_基础语法部分