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. C# winform 中 TabControl 动态显示 TabPage

    在winform应用中,tabcontrol是一个很好的控件,可以根据需求提供多个选项卡(TabPages),但是有一个问题是当某个项目需要多个选项卡,但是不同的功能要求显示不同的选项卡,其他的非该功 ...

  2. jquery批量控制form禁用的代码

    jquery批量控制form禁用的代码. 代码: <script type="text/javascript" src="/jquery/jquery-1.8.2. ...

  3. How to using x++ creating Vendors [AX2012]

    .//Create party for the vendor public void createParty(VendorRequestCreate _vendorRequestCreate) { ; ...

  4. 22 高级SQL特性

    1.约束 为正确地进行关系数据库设计,需要一种方法来保证只在表中插入合法的数据.例如,如果Orders表存储订单信息,OrderItems表存储订单详细内容,应该保证Orderitems中引用的任何订 ...

  5. 使用PowerShell 连接Azure

    除了使用门户登入外,还可以使用PowerShell的方式来连接Azure.首先要去下载组件 http://azure.microsoft.com/en-us/downloads/?rnd=1 http ...

  6. JMS消息头

    一个消息对象分为三部分:消息头(Headers),属性(Properties)和消息体(Payload).对于StreamMessage和MapMessage,消息本身就有特定的结构,而对于TextM ...

  7. Oracle中的通配符

    这是scott用户下的EMP表 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 7369 SMITH CLERK 7902 1980/12/17 800   ...

  8. 按键消抖VERILOG实现

    对于消抖,有很多种写法.今天分享一下我的写法. 基本思路: 1. 看图                     图1                                           ...

  9. iOS 系统二维码扫描(可限制扫描区域)

    使用 AVFoundation系统库来进行二维码扫描并且限制扫描二维码的范围.(因为默认的是全屏扫描) -(void)beginCode { //1.摄像头设备 AVCaptureDevice *de ...

  10. 类的const成员

    类的const成员包括const数据成员和const成员函数: 1.const数据成员: 和普通的const变量一样,定义时初始化,且不能修改 2.const成员函数: const成员函数只能访问其他 ...