FatMouse' Trade

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

  1. 5 3
  2. 7 2
  3. 4 3
  4. 5 2
  5. 20 3
  6. 25 18
  7. 24 15
  8. 15 10
  9. -1 -1

Sample Output

  1. 13.333
  2. 31.500
  1. //本题是简单贪心问题。意思是老鼠有m榜猫粮,通过给猫粮东西data[i].b能够兑换data[i].a,求最多能够兑换多少食物。
  2. //仅仅需将data[i].a/data[i].b的值从大到小排序就可以求解。
  3. #include<stdio.h>
  4. struct st
  5. {
  6.     double a;
  7.     double b;
  8.     double c;
  9. }data[1000];
  10. int main()
  11. {
  12.     int i,j,m,n;
  13.     struct st data[1000],t;
  14.     while(scanf("%d %d",&m,&n)&&(m!=-1||n!=-1))
  15.     {
  16.         double sum=0.000;
  17.         for(i=0;i<n;i++)
  18.         {
  19.             scanf("%lf %lf",&data[i].a,&data[i].b);
  20.         }
  21.         for(i=0;i<n;i++)
  22.         {
  23.             for( j=i+1;j<n;j++)
  24.             {
  25.                 if((data[i].a/data[i].b)<data[j].a/data[j].b)
  26.                 {
  27.                 t=data[i];
  28.                 data[i]=data[j];
  29.                 data[j]=t;}
  30.             }
  31.         }
  32.         for(i=0;i<n;i++)
  33.         {
  34.             if(m-data[i].b>=0.001)
  35.             {
  36.                 sum+=data[i].a;
  37.                 m-=data[i].b;
  38.             }
  39.             else
  40.             {
  41.                 sum=sum+m*data[i].a/data[i].b;
  42.                 break;
  43.             }
  44.         }
  45.         printf("%.3lf\n",sum);
  46.     }
  47.     return 0;
  48. }

FatMouse&#39; Trade(杭电1009)的更多相关文章

  1. 杭电 1009 FatMouse' Trade (贪心)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  2. HDU 1009:FatMouse&#39; Trade(简单贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu 1009 FatMouse&#39; Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. ZOJ 2109 FatMouse&#39; Trade (背包 dp + 贪婪)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat ...

  5. 杭电--1009 C语言实现

    思路:要用有限的猫粮得到最多的javabean,则在房间中得到的javabean比例应尽可能的大. 用一个结构体,保存每个房间中的javabean和猫粮比例和房间号,然后将结构体按比例排序,则从比例最 ...

  6. 杭电ACM分类

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

  7. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  8. 杭电ACM题单

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

  9. 杭电acm习题分类

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

随机推荐

  1. Beginning MyBatis 3 Part 2 : How to Handle One-to-Many and One-to-One Selects

    One of the latest MyBatis feature is the ability to use Annotations or XML to do One-to-One or One-t ...

  2. 在 Perl看来, 字符串只有两种形式. 一种是octets, 即8位序列, 也就是我们通常说的字节数组. 另一种utf8编码的字符串, perl管它叫string. 也就是说: Perl只熟悉两种编

    在 Perl看来, 字符串只有两种形式. 一种是octets, 即8位序列, 也就是我们通常说的字节数组. 另一种utf8编码的字符串, perl管它叫string. 也就是说: Perl只熟悉两种编 ...

  3. bzoj 1030-1039

    1030 JSOI2007 文本生成器 AC自动机加DP即可. 1031 JSOI2007 字符加密Cipher 后缀数组即可. 1032 JSOI2007 祖码Zuma 数据有问题. 设\(f(l, ...

  4. java模拟实现生产者---消费者问题

    本文章为小编原创,请尊重文章的原创性,转载请注意写明转载来源:http://blog.csdn.net/u012116457 已知技术參数: 生产者消费者问题,描写叙述一组生产者向一组消费者提供产品/ ...

  5. MSSQL - 备份和还原数据库

    SQL语句备份和还原数据库:http://blog.csdn.net/liuhelong/article/details/3335687 1.MSSQL - SqlServer:此数据库处于单用户模式 ...

  6. checkbox探究

    介绍checkbox checkbox: A check box. You must use the value attribute to define the value submitted by ...

  7. static在C和C++中的用法和区别

    static主要有三个作用: (1)局部静态变量 (2)外部静态变量/函数 (3)静态数据成员/成员函数 前两种C和C++都有,第三种仅在C++中有,下面分别作以下介绍: 一.局部静态变量 在C/C+ ...

  8. 基于visual Studio2013解决C语言竞赛题之1034数组赋值

          题目 解决代码及点评 /********************************************************************** ...

  9. libevent简单介绍和使用

    <pre class="html" name="code">libevent接口的使用是简单easy的.关键还是一些其他技术须要深入了解.如epol ...

  10. Eclipse用法和技巧十五:自动添加未实现方法1

    java代码中经常要实现一些接口,这个也是java代码独有的地方.实现接口,就意味着要实现这个接口中定义的方法,如果一个个去码出方法就需要记得方法名称等等,就算有内容辅助快捷键帮助,也是很麻烦的.这里 ...