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. SequoiaDB 与 Hive 集成

    SequoiaDB与Hadoop部署 SequoiaDB与Hadoop在物理上部署方案如下图所示,部署建议如下: l  SequoiaDB与Hadoop部署在相同的物理设备上,以减少Hadoop与Se ...

  2. 为msysgit增加vim语法高亮文件

    在win7下装了msysgit,今天我遇到一个不爽的问题,打开git bash,用vim打开一个xml文件 结果都是黑屏的,没语法高亮,这个必须不能忍啊,我找到msysgit的安装目录,发现Vim73 ...

  3. php 获取链接参数

    private function getQuerystr($url,$key){        $res = '';        $a = strpos($url,'?');        if($ ...

  4. java 环境变量设置

    JAVA_HOME  C:\Program Files\Java\jdk1.7.0 PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; CLASSPATH .;%JAV ...

  5. .NET书籍推荐

    任何语言的学习,要快速掌握,不在看书,而在实践.——题记 .NET技术从1.1发展到2.0,内核基本完善,从.NET 2.0开始学习是个明智的选择.而NET 3.5以及即将推出的.NET 4.0所新加 ...

  6. Mac OS X 10.10.2 Yosemite jdk 环境变量配置

    我的Mac系统版本是OS X 10.10.2 Yosemite,为了用Eclipse做android开发,安装了jdk 1.7, 但是如果想使用IntelliJ IDE做android开发的话,就需要 ...

  7. Scrumworks乱码

    要搞敏捷,先找个工具.选了scrumworks5.1.安装完后发现录入汉字乱码. 环境: server:CentOS linux db:mysql5.0 appserver:jboss(scrumwo ...

  8. Objective-C的内省(Introspection)小结

    内省(Introspection)是面向对象语言和环境的一个强大特性,Objective-C和Cocoa在这个方面尤其的丰富.内省是对象揭示自己作为一个运行时对象的详细信息的一种能力.这些详细信息包括 ...

  9. C++中的仿函数,std::function和bind()的用法

    1.仿函数:又叫std::function,是C++中的一个模板类 2.C语言中的函数指针: int  add(int a,int b) { return a+b; } typedef int (*f ...

  10. Hadoop启动异常情况解决方案

    1. 启动时报WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using b ...