FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 103515    Accepted Submission(s): 36159

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.
 
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 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
 
Sample Output
13.333
31.500
 
Author
CHEN, Yue
 
Source
 
题意:

这一道题意思就是老鼠用猫食物换取自己最喜爱的食物javaBean的过程,当然换取的最终结果是保证最后的JavaBean是最多的,

而且是当自己手中的猫食物小于每个仓库所需交换的猫食物时候,可以手中有多少就交换多少。

所以在解这道题时候要想到按照每个仓库javaBean最大的比率排序才能保证最后的交换的javaBean是最大的。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. using namespace std;
  5. const int maxn = 1e3+;
  6. int m,n;
  7. struct node{
  8. int j,f;
  9. double r;
  10. } food[maxn];
  11. class cmp{
  12. public:
  13. bool operator()(node a,node b)const{
  14. return a.r>b.r;
  15. }
  16. };
  17. int main(){
  18. while(~scanf("%d%d",&m,&n)){
  19. if(m==-) break;
  20. for(int i=; i<n; i++ ){
  21. cin>>food[i].j>>food[i].f;
  22. food[i].r=1.0*food[i].j/food[i].f;
  23. }
  24. sort(food,food+n,cmp());
  25. double ans=;
  26. for( int i=; i<n; i++ ){
  27. if(m>=food[i].f){
  28. ans+=food[i].j;
  29. m-=food[i].f;
  30. }
  31. else{
  32. if(m==) break;
  33. else{
  34. ans+=m*food[i].r;
  35. break;
  36. }
  37. }
  38. }
  39. printf("%.3f\n",ans);
  40. }
  41. return ;
  42. }
 

FatMouse' Trade(杭电ACM---1009)的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  3. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  4. 2017杭电ACM集训队单人排位赛 - 6

    2017杭电ACM集训队单人排位赛 - 6 排名 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 59 1 X X 1 1 X X 0 1 ...

  5. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  6. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  7. 杭电acm阶段之理工大版

    想參加全国软件设计大赛C/C++语言组的同学,假设前一篇<C和指针课后练习题总结>没看完的,请先看完而且依照上面的训练做完,然后做以下的训练. 传送门:http://blog.csdn.n ...

  8. 杭电acm 1076题

    水题,一个求闰年的题目,复习一下闰年的求法.... 1,如果能被4整除但不能被100整除的是闰年 2,能被400整除的是闰年 题目大意是:给定一个开始年份T以及一个正数N,要求求出从T开始,到了哪一年 ...

  9. 杭电acm 1037题

    本题应该是迄今为止最为简单的一道题,只有一组输入,输出也简单.... /****************************************** 杭电acm 1037题 已AC ***** ...

  10. 杭电acm 1038题

    本题比较简单,但是需要掌握几个小技巧,先上代码 /************************************* 杭电ACM 1038题,已AC ********************* ...

随机推荐

  1. 国际化之Android设备支持的语种

    昨天发了关于iOS支持的语种,文章最后也补了安卓支持语种列表.但最后发现安卓设备支持跟它列的有出入,我重新完全手工整理了一遍. 我将对应的语种在安卓的语言列表里的显示,也全部逐一列出来了,方便大家到时 ...

  2. shell符号解释

    #符号详解 () 在子shell中运行 (a=1);echo $a,结果是空,因为a=1不是在当前shell中运行的(a=1);(echo $a)也是空的 小技巧:(cd $path, do some ...

  3. 【C++】C++中的流

    目录结构: contents structure [-] 1.IO类 IO对象无拷贝状态 条件状态 文件流 文件模式 string流 1.IO类 除了istream和ostream之外,标准库还定义了 ...

  4. EF+LINQ事物处理 C# 使用NLog记录日志入门操作 ASP.NET MVC多语言 仿微软网站效果(转) 详解C#特性和反射(一) c# API接受图片文件以Base64格式上传图片 .NET读取json数据并绑定到对象

    EF+LINQ事物处理   在使用EF的情况下,怎么进行事务的处理,来减少数据操作时的失误,比如重复插入数据等等这些问题,这都是经常会遇到的一些问题 但是如果是我有多个站点,然后存在同类型的角色去操作 ...

  5. sql中的left join以及on、where关键字的区别

    创建两张表并插入一些数据 create table class( class_id int, class_name ), class_grade ) ); ,'语文','A'); ,'数学','B') ...

  6. PHP事件机制

    先用 3W1H(who what why how) 分析法的思路来解释一下 事件机制, 更重要的是, 这个有什么用. 正常的程序执行, 或者说人的思维趋势, 都是按照 时间线性串行 的, 保持 连续性 ...

  7. Xcode No account for team "". Add a new account in the Accounts preference pane or verify that your accounts have valid credentials.

    问题背景 Xcode报错误信息:No account for team "QMP96B5DPW". Add a new account in the Accounts prefer ...

  8. Atitit 最近资料文章列表r9 r8 月份 attilax总结

    Atitit 最近资料文章列表r9  r8 月份   attilax总结 atitit tag标签标示规范 attilax总结 v2 r922.docx 2017-09-28 02:04 阅读(27) ...

  9. [CI]jenkins安装&插件管理&java-helloworld之旅

    持续集成概述 没有持续集成时的情况 持续集成最佳实战 维护一个单一的代码库 使构建自动化 执行测试是构建的一部分 集成日志及历史记录 使用统一的依赖包管理库 每天至少集成一次 jenkins实现持续集 ...

  10. Asp.Net WebApi接口返回值IHttpActionResult

    WebApi是微软在VS2012 MVC4版本中绑定发行的,webapi2.0同mvc5发行的 webapi一共有以下接口返回值 1.void无返回值2.IHttpActionResult Json( ...