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


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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f struct node
{
int a,b;
double c;
} p[10000]; bool cmp(node a,node b)
{
return a.c>b.c;
} int main()
{
int m,n;
while(~scanf("%d%d",&m,&n))
{
if(m==-1&&n==-1)
break;
for(int i=0; i<n; i++)
{
scanf("%d%d",&p[i].a,&p[i].b);
p[i].c=p[i].a*1.0/p[i].b;
}
sort(p,p+n,cmp);
double ans=0;
for(int i=0;i<n;i++)
{
if(m>p[i].b)
{
ans+=p[i].a;
m-=p[i].b;
}
else
{
ans+=m*p[i].c;
break;
}
}
printf("%.3f\n",ans); }
return 0;
}

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. c#设计模式3抽象工厂模式(Abstract Factory)

    #region 坦克系列 abstract class Tank { abstract public void Go(); } /// <summary> /// 越野车 /// < ...

  2. 25.mysql中的常用工具

    25.mysql中的常用工具25.1 mysql客户端连接工具跳转至mysql安装目录下的bincd C:\Program Files\MySQL\MySQL Server 5.7\binmac下cd ...

  3. L1-033 出生年(15)(STL-set代码)

    L1-033 出生年(15 分) 以上是新浪微博中一奇葩贴:"我出生于1988年,直到25岁才遇到4个数字都不相同的年份."也就是说,直到2013年才达到"4个数字都不相 ...

  4. PAT 1016 部分A+B(15)(C++&JAVA&&Python)

    1016 部分A+B(15 分) 正整数 A 的"D​A​​(为 1 位整数)部分"定义为由 A 中所有 D​A​​ 组成的新整数 P​A​​.例如:给定 A=3862767,D​ ...

  5. UEFI、BIOS、Secure Boot的关系和知识介绍

      从Windows 8操作系统时代开始,安装操作系统的方法也有了很大的改变,Windows 8采用了Secure Boot引导启动的方式,而不是过去Win XP和Win 7的Legacy启动方式,从 ...

  6. BZOJ1178或洛谷3626 [APIO2009]会议中心

    BZOJ原题链接 洛谷原题链接 第一个问题是经典的最多不相交区间问题,用贪心即可解决. 主要问题是第二个,求最小字典序的方案. 我们可以尝试从\(1\to n\)扫一遍所有区间,按顺序对每一个不会使答 ...

  7. POJ3694 Network - Tarjan + 并查集

    Description 给定$N$个点和 $M$条边的无向联通图, 有$Q$ 次操作, 连接两个点的边, 问每次操作后的图中有几个桥 Solution 首先Tarjan找出边双联通分量, 每个双联通分 ...

  8. Ubuntu12.04(64bit)下安装Qt4总结

    本文主要介绍linux系统Ubuntu12.04(64bit)下Qt4.8.5的安装,其中还涉及Fedora9下Qt4的安装. 1.下载软件:去Qt的官网下载Qt4.8.5和Qt Creator软件, ...

  9. SQL Server 2008数据库连接错误

    以Windows身份连接SQL Server 2008数据库时,连接不上,出现如下报错画面: 解决办法:打开services窗口,找到名字类似于SQL Server (xxx)的服务,启动服务. 注: ...

  10. Netty 源码(二)NioEventLoop 之 Channel 注册

    Netty 源码(二)NioEventLoop 之 Channel 注册 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一 ...