FatMouse' Trade

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

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
 
 #include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct ln{
double x;
double y;
double weight;
}a[];
int cmp(const void*a,const void*b)
{
return (*(struct ln*)a).weight<(*(struct ln*)b).weight?:-;
}
int main()
{
//freopen("in.txt","r",stdin);
int m,n;
while(~scanf("%d%d",&m,&n))
{
memset(a,,sizeof(a));
if(m==-&&n==-)
break;
for(int i=;i<n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].weight=a[i].x/a[i].y;
}
qsort(a,n,sizeof(struct ln),cmp);
double sum=; for(int i=;i<n;i++)
{
if(m>=a[i].y)
{
sum+=a[i].x;
m-=a[i].y;
}
else
{
sum+=a[i].weight*m;
m=;
}
}
printf("%.3lf\n",sum);
}
return ;
}
 
 

1009 FatMouse' Trade的更多相关文章

  1. HDU 1009 FatMouse' Trade(简单贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  2. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  3. HDOJ.1009 FatMouse' Trade (贪心)

    FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...

  4. Hdu 1009 FatMouse' Trade

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

  5. hdu 1009:FatMouse' Trade(贪心)

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

  6. Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏

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

  7. HDU 1009 FatMouse' Trade(贪心)

    FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...

  8. Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏

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

  9. HDU 1009 FatMouse' Trade【贪心】

    解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...

随机推荐

  1. 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计

    本帖最后由 xinxincaijq 于 2013-1-9 10:27 编辑 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计 转自博客:http:// ...

  2. visual studio中创建单元测试

    1 打开  工具--自定义 2 选择 上下文菜单--编辑器上下文菜单|代码窗口 3 在这里我们可以看到“创建单元测试”这个菜单了,将它移到运行测试菜单下面 4 关闭VS并重启 重启后再对着类名,点击右 ...

  3. trade 1.0 开源工具

    dapper.net T4PocoGenerator/ Dapper.ColumnMapper 参考链接: http://blog.csdn.net/ymnets/article/details/85 ...

  4. 解决前端浏览器传JSON对像到服务端后全部变成string类型的方法

    这几天公司用nodejs+mongodb来做些东西,UI用的是kendo UI 碰到一个问题: 举个例子var a={"name":"张三","age ...

  5. C语言文件函数

    FILE *fp: 其中的FILE应该大写,它实际上是系统定义的一个结构,在stdio.h文件中.该结构中有文件名,文件状态,文件当前的读写信息等. fp是指向FILE结构的指针变量,通过fp可以找到 ...

  6. 表达式语言之EL表达式

    1.EL的用法EL的起源:起源于JSTL.EL运算符: 算术型:+.-.*./.div.%.mod.其中/和div都表示求除.%和mod表示求余数. 逻辑型:and或&&.or或||. ...

  7. IE中出现 "Stack overflow at line" 错误的解决方法

    在做网站时遇到一个问题,网站用的以前的程序,在没有改过什么程序的情况下,页面总是提示Stack overflow at line 0的错误,而以前的网站都正常没有出现过这种情况,在网上找了一下解决办法 ...

  8. Python实战(2)

    在安装python第三方插件库的时候遇到了这个错误 遇到这种问题可以”转战“国内的第三方镜像,问题便可迎刃而解.例如豆瓣镜像——http://pypi.douban.com/simple/ 先安装ea ...

  9. Daily Scrum 11.11

    摘要:本次会议继续讨论程序的问题以及单元测试和集成测试,本次测试为1.02版本.本次的Task列表如下: Task列表 出席人员 Today's Task Tomorrow's Task 刘昊岩  t ...

  10. 学习KnockOut第一篇之Hello World

    学习KnockOut第一篇之Hello World 笔者刚开始学习KnockOut.写的内容就相当于一个学习笔记.且在此处向官网致敬,比较喜欢他们家的Live Example版块,里面有jsFiddl ...