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. hdu 2066 ( 最短路) Floyd & Dijkstra & Spfa

    http://acm.hdu.edu.cn/showproblem.php?pid=2066 今天复习了一下最短路和最小生成树,发现居然闹了个大笑话-----我居然一直写的是Floyd,但我自己一直以 ...

  2. Canvas绘图 (html5新增特性)

    Canvas 使用<canvas>对象,需要设置属性:width,height.指定绘图的区域大小.在canvas标签前后出现的信息将在不支持<canvas>元素的浏览器中显示 ...

  3. C&Cpp.CallGraph

    1. CodeViz http://www.skynet.ie/~mel/projects/codeviz/ 2. http://my.oschina.net/zmlblog/blog/186308

  4. Jsonpath的基本使用

    JSONPath - 是xpath在json的应用. xml最大的优点就有大量的工具可以分析,转换,和选择性的提取文档中的数据.XPath是这些最强大的工具之一.   如果可以使用xpath来解析js ...

  5. 数据结构和Java集合

    list接口,可重复,有序的.list有arrayList,因为是数组结构,适合用在数据的查询,linkedList,因为是链表结构,适合用在增删操作.数组如果增删的话,需要后面的元素都往前或者往后移 ...

  6. 可以用WebRTC来做视频直播吗?

    https://www.zhihu.com/question/25497090   作者:韦易笑链接:https://www.zhihu.com/question/25497090/answer/72 ...

  7. Peter的烟(水题测试2017082401&洛谷1150)

    题目链接:Peter的烟 这道题基本做法很水,不解释. #include<bits/stdc++.h> using namespace std; int main(){ int n,k; ...

  8. Django学习经验

    1.在1.9——>到2.0的版本中, Django.core.urlresolvers import reverse ——>django.urls 2.当无法访问时把原来的数据清空: 首先 ...

  9. MVC 开发模式

    1.M:Model  模型:实体类和业务和dao 2.V:view  视图:JSP 3.C:Controller  控制器:servlet 3.1 作用:视图和逻辑分离 4.MVC适用场景:大型项目开 ...

  10. 2018.12.30 bzoj3027: [Ceoi2004]Sweet(生成函数+搜索)

    传送门 生成函数好题. 题意简述:给出n个盒子,第iii个盒子里有mim_imi​颗相同的糖(但不同盒子中的糖不相同),问有多少种选法可以从各盒子中选出数量在[a,b][a,b][a,b]之间的糖果. ...