FatMouse’ Trade

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 63198 Accepted Submission(s): 21342

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


简单贪心题,按性价比排序后优先取大的

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <queue>
  7. #include <stack>
  8. #include <string>
  9. #include <set>
  10. #include<vector>
  11. #include <map>
  12. using namespace std;
  13. #define inf 0x3f3f3f3f
  14. struct node
  15. {
  16. int a,b;
  17. double c;
  18. } p[10000];
  19. bool cmp(node a,node b)
  20. {
  21. return a.c>b.c;
  22. }
  23. int main()
  24. {
  25. int m,n;
  26. while(~scanf("%d%d",&m,&n))
  27. {
  28. if(m==-1&&n==-1)
  29. break;
  30. for(int i=0; i<n; i++)
  31. {
  32. scanf("%d%d",&p[i].a,&p[i].b);
  33. p[i].c=p[i].a*1.0/p[i].b;
  34. }
  35. sort(p,p+n,cmp);
  36. double ans=0;
  37. for(int i=0;i<n;i++)
  38. {
  39. if(m>p[i].b)
  40. {
  41. ans+=p[i].a;
  42. m-=p[i].b;
  43. }
  44. else
  45. {
  46. ans+=m*p[i].c;
  47. break;
  48. }
  49. }
  50. printf("%.3f\n",ans);
  51. }
  52. return 0;
  53. }

Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏的更多相关文章

  1. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. ZOJ2478 Encoding 2017-04-18 23:02 43人阅读 评论(0) 收藏

    Encoding Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a string containing only 'A' - 'Z', ...

  3. POJ3281 Dining 2017-02-11 23:02 44人阅读 评论(0) 收藏

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

  4. ImageView一例 分类: H1_ANDROID 2013-10-30 23:02 1812人阅读 评论(0) 收藏

    参考自<疯狂android讲义>2.4节 效果如下: 当点击图上某点时,将之附近放大至下图. 布局文件: <LinearLayout xmlns:android="http ...

  5. HDU 2101 A + B Problem Too 分类: ACM 2015-06-16 23:57 18人阅读 评论(0) 收藏

    A + B Problem Too Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...

  7. HDU 2040 亲和数 [补] 分类: ACM 2015-06-25 23:10 10人阅读 评论(0) 收藏

    今天和昨天都没有做题,昨天是因为复习太累后面忘了,今天也是上午考毛概,下午又忙着复习计算机图形学,晚上也是忘了结果打了暗黑3,把暗黑3 打通关了,以后都不会玩太多游戏了,争取明天做3题把题目补上,拖越 ...

  8. HDU 2034 人见人爱A-B 分类: ACM 2015-06-23 23:42 9人阅读 评论(0) 收藏

    人见人爱A-B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  9. HDU 2035 人见人爱A^B 分类: ACM 2015-06-22 23:54 9人阅读 评论(0) 收藏

    人见人爱A^B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

随机推荐

  1. Linux netstat

    一.简介   二.语法   三.实例 1)查看TCP连接数 netstat -n | awk '/^tcp/ {++S[$NF]} END {for (a in S) print a, S[a]}'

  2. 8I - 吃糖果

    HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样:可是Gardon不知道是否存在一种吃 ...

  3. XHR的对象及用法

    function  createXHR(){         //检测原生XHR对象是否存在,如果存在刚返回它的新实例:     //如果不存在,则检测ActiveX对象;     //如果两个都不存 ...

  4. js分割数字

    var str = "123"; var b = String(str).split(''); 打印b[0].b[1].b[2]看效果...

  5. hdu 5493 (2015合肥网赛) Queue

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意,t组数据,n个人,n行每行分别是人的身高和这个人的左边或右边比他高的人的个数,输出符合条件 ...

  6. UI设计教程分享:Ps合成炫酷机械姬

    本次给大家分享一个通过PS合成一个炫酷的机械姬,在这个教程里给大家展示图像的色彩处理.人物光影塑造和创意实现及细节处理,教程比较简单,创意十足,看过<机械姬>电影的同学们一定知道这个有多炫 ...

  7. PS故障风海报制作技术分享

    1.首先找一张看起来很酷的图(也可以选择自己喜欢的图片): 2. 复制图层,点击添加图层样式,选择混合选项,在高级混合里面的通道选项,有R.G.B三个通道选项,默认是全部勾选的状态,选择其中一个勾掉( ...

  8. Spring中@Autowired注解、@Resource注解的区别 (zz)

    Spring中@Autowired注解.@Resource注解的区别 Spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resource.@ ...

  9. mybatis学习六 parameterType 属性

    1. 在 XXXMapper.xml 中<select><delete>等标签的 parameterType 可以控制参数类型2. SqlSession 的 selectLis ...

  10. unity延时函数

    新建一个工具类 public class DelayToInvoke : MonoBehaviour{ public static IEnumerator DelayToInvokeDo(Action ...