824 Greedy Mouse
来源:互联网 发布:淘宝联盟怎么做高佣 编辑:程序博客网 时间:2024/05/29 09:55
Greedy Mouse
时间限制:1000 ms | 内存限制:65535 KB
难度:3
- 描述
A fat mouse prepared M pounds of cat food,ready to trade with the cats guarding the warehouse containing his
favorite food:peanut. The warehouse has N rooms.The ith room containsW[i] pounds of peanut and requires
F[i] pounds of cat food. Fatmouse does not have to trade for all the peanut in the room,instead,he may get
W[i]*a% pounds of peanut if he pays F[i]*a% pounds of cat food.The mouse is a stupid mouse,so can you tell
him the maximum amount of peanut he can obtain.
- 输入
- The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers W[i] and F[i] respectively. The test case is terminated by two -1. All integers are not greater than 1000.
- 输出
- For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of penaut that FatMouse can obtain.
- 样例输入
5 37 24 35 220 325 1824 1515 10-1 -1
- 样例输出
13.33331.500
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){ int i,j,m,n; int w[1001],f[1001]; double max,v[1001]; while(scanf("%d%d",&m,&n)!=EOF && !((m==-1)&&(n==-1))) { max=0; for(i=0;i<n;i++) { scanf("%d%d",&w[i],&f[i]); v[i]=1.0*w[i]/f[i]; } for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(v[i]<v[j]) { swap(w[i],w[j]); swap(f[i],f[j]); swap(v[i],v[j]); } for(i=0;i<n;i++) { if(m-f[i]<=0) { max+=1.0*m*v[i]; break; } else { max+=w[i]; m-=f[i]; } } printf("%.3lf\n",max); }}
0 0
- NYOJ 824 Greedy Mouse
- NYOJ-824 Greedy Mouse
- NYOJ 824 Greedy Mouse
- 824 Greedy Mouse
- NYOJ 824 Greedy Mouse
- nyoj 824 Greedy Mouse
- nyoj 824 Greedy Mouse【贪心】
- Greedy Mouse
- Greedy Mouse
- NYOJ824 Greedy Mouse
- NYOJ - 824 - Greedy Mouse(贪心算法--部分背包问题)
- Greedy Mouse 贪心的耗子 nyoj824(贪心算法)
- Mouse
- mouse
- mouse
- Mouse
- mouse
- Greedy
- 822 画图
- NSMutableString字符串删除最后一个字符串
- SAP Mobile Documents 资料收集
- hdu 1098
- Oracle中使用alter table来增加,删除,修改列的语法
- 824 Greedy Mouse
- Uva 12723 期望
- Algorithm Gossip: 费式数列
- c#编程中遇到的错误 持续更新
- tornado+ansible+twisted+mongodb运维自动化系统开发(三)
- 833 取石子(七)
- .NET创建、删除、复制文件夹及其子文件的实例方法
- hdu2018 母牛的故事
- jqgrid 实现行编辑,表单编辑的列联动