FatMouse' Trade


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 <vector>
#include <algorithm>
using namespace std;
typedef struct fm{
int j, f;
double aver;
} room; bool cmp(const room &a, const room &b){
return a.aver > b.aver;
} int main(){
int m, n;
cout.precision();
vector<room> v;
while(cin >> m >> n){
if(m == - && n == -)
break;
v.clear();
for(int i = ; i < n; i++){
room rm;
v.push_back(rm);
cin >> v[i].j >> v[i].f;
v[i].aver = double(v[i].j) / v[i].f;
}
sort(v.begin(), v.end(), cmp);
double sum = ;
for(int i = ; i < n; i++){
if(m > v[i].f){
sum += v[i].j;
m -= v[i].f;
} else {
sum += (double)m * v[i].j / v[i].f;
break;
}
}
cout << fixed << sum << endl;
}
return ;
}

zoj 2109 FatMouse' Trade的更多相关文章

  1. ZOJ 2109 FatMouse&#39; Trade (背包 dp + 贪婪)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1109 FatMouse prepared M pounds of cat ...

  2. Hdu 1009 FatMouse' Trade

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

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

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

  4. 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) ...

  5. 1009 FatMouse' Trade

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

  6. FatMouse' Trade

    /* problem: FatMouse' Trade this is greedy problem. firstly:we should calculate the average J[i]/F[i ...

  7. HDU1009 FatMouse' Trade

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

  8. HDU 1009 FatMouse' Trade(贪心)

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

  9. FatMouse' Trade -HZNU寒假集训

    FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...

随机推荐

  1. HTML中div的悬浮标题

    <div title="我是鼠标悬停文字">我是一个DIV</div> <div class="diggao" title=&qu ...

  2. vs2010 坑爹的BUG

    以前用VS2005的时候,就遇到过一些很奇怪的BUG,比如始终报错,然后把项目文件删除,重新创建一个项目文件,就好了. 今天用VS2010测试程序时,又发现一个坑爹的BUG,这绝对不是我的错! sta ...

  3. vue 模拟后台数据(加载本地json文件)调试

    首先创建一个本地json文件,放在项目中如下 { "runRedLight":{ "CurrentPage": 1, "TotalPages" ...

  4. 可能是最漂亮的Spring事务管理详解 专题

    微信阅读地址链接:可能是最漂亮的Spring事务管理详解 事务概念回顾 什么是事务? 事务是逻辑上的一组操作,要么都执行,要么都不执行. 事物的特性(ACID): 原子性: 事务是最小的执行单位,不允 ...

  5. 【学习笔记】二:在HTML中使用JavaScript

    1.<script>标签 1)考虑到最大限度的浏览器兼容性和约定俗成,type属性使用:text/javascript. 2)标签建议放置到</body>标签前,提高用户体验( ...

  6. jacob的使用方法

    网上一大堆你抄我的,我抄你的,但基本配置都没说清,做个笔记让后来的人少走冤枉路 1.下载最新的jacob,jdk版本一一对应,1.6对应jacob的1.16,1.7对应1.17.... 2.应用程序将 ...

  7. SQL系列学习 存储过程&事物语法

    /*学习事物基本语法*/ /*增加课室名的唯一索引*/ ALTER table class add constraint uni_ClassName unique(name) /*创建存储过程,其中增 ...

  8. HYSBZ 1588 营业额统计 (Splay树)

    题意:给出一个公司每一天的营业额,求每天的最小波动值之和.该天的最小波动值= min { 绝对值| 该天以前某一天的营业额-该天的营业额 | }.第一天的最小波动值就是其自己. 思路:Splay伸展树 ...

  9. COGS 1361. 树

    ★   输入文件:treed.in   输出文件:treed.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 在一个凉爽的夏夜,xth和rabbit来到花园里砍树.为啥 ...

  10. Dreamoon and MRT

    Dreamoon and MRT 题目链接: http://codeforces.com/group/gRkn7bDfsN/contest/212299/problem/B 只需要考虑相对位置,设a0 ...