hdu 1009 FatMouse' Trade
来源:互联网 发布:gulp.js 编辑:程序博客网 时间:2024/05/20 13:18
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43036 Accepted Submission(s): 14376
Problem Description
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
Input
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 J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
Sample Input
5 37 24 35 220 325 1824 1515 10-1 -1
Sample Output
13.33331.500/*题解: 简单的贪心问题,老方法,先排序 */#include<cstdio>#include<algorithm>using namespace std;struct FM{ double a; double b;}e[10010];int cmp(FM a,FM b){ return a.a/(a.b*1.0)>b.a/(b.b*1.0);}int main(){ int m,n,i,j; double sum,t; while(scanf("%d %d",&m,&n)&&(n!=-1&&m!=-1)) { for(i=0; i<n; i++) scanf("%lf %lf",&e[i].a,&e[i].b); sort(e,e+n,cmp); for(i=0,sum=0.0,t=0.0; i<n; i++) { if(t+e[i].b<m) { sum+=e[i].a; t+=e[i].b; } else { sum+=(m-t)*(e[i].a/(e[i].b*1.0)); break; } } printf("%.3lf\n",sum); } return 0;}
0 0
- HDU 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 - FatMouse' Trade
- HDU-1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU--1009--FatMouse' Trade
- hdu 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU-1009 FatMouse' Trade
- 《html, css, javascritp网页制作》 刘西杰
- 【转】Visual Studio 2012 与此版本的 Windows 不兼容 解决
- 做程序猿的老婆应该注意的一些事情
- 海关发公告打击海外代购 朋友圈代购或被认为走私
- Android UI开发详解之ActionBar
- hdu 1009 FatMouse' Trade
- 国际顶级中文域名“.网址”全球开放注册
- C# 与 C++交互的重要细节 结构体传递 数组传递 等 stdcall
- C语言-------多进程编程
- 俄罗斯黑客窃取全球12亿用户信息 42万家网站受影响
- P2P网贷7月份迎来小高潮 10月份可能会出现倒闭潮
- 篡改账号转卖比特币 警方打掉新型网络犯罪团伙
- __VA_ARGS__用法(转)
- 5.1-位的子串