Greedy Mouse

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

A fat mouse prepared M pounds of cat food,ready to trade with the cats guarding the warehouse containing his

favorite food:peanut. The warehouse has N rooms.The ith room containsW[i] pounds of peanut and requires

F[i] pounds of cat food. Fatmouse does not have to trade for all the peanut in the room,instead,he may get

W[i]*a% pounds of peanut if he pays F[i]*a% pounds of cat food.The mouse is a stupid mouse,so can you tell

him the maximum amount of peanut he can obtain.

 
输入
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 W[i] and F[i] respectively. The test case is terminated by two -1. All integers are not greater than 1000.
输出
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of penaut that FatMouse can obtain.
样例输入
  1. 5 3
  2. 7 2
  3. 4 3
  4. 5 2
  5. 20 3
  6. 25 18
  7. 24 15
  8. 15 10
  9. -1 -1
样例输出
  1. 13.333
  2. 31.500
    基本的背包问题,用贪心求解
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cstdio>
  5. #include <utility>
  6. using namespace std;
  7. typedef pair<double,double> W;
  8. bool cmp(const W& a,const W& b){ return a.first > b.first;}
  9. int main(){
  10. double m;
  11. int n;
  12. while(cin >> m >> n && m!=- && n!=-){
  13. vector<W> exchange(n);
  14. for(int i = ; i < n; ++ i){
  15. double w,f;
  16. cin >>w >>f;
  17. exchange[i].first = w/f;
  18. exchange[i].second = w;
  19. }
  20. sort(exchange.begin(),exchange.end(), cmp);
  21. double res = ;
  22. for(int i = ; i < n && m; ++i){
  23. if(m > exchange[i].second/exchange[i].first){
  24. res += exchange[i].second;
  25. m -= exchange[i].second/exchange[i].first;
  26. }else{
  27. res+=m*exchange[i].first;
  28. break;
  29. }
  30. }
  31. printf("%0.3f\n",res);
  32. }
  33. }
  1.  
  1.  

ACM Greedy Mouse的更多相关文章

  1. POJ1386Play on Words[有向图欧拉路]

    Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11846   Accepted: 4050 De ...

  2. SPOJ Play on Words

    传送门 WORDS1 - Play on Words #graph-theory #euler-circuit Some of the secret doors contain a very inte ...

  3. Play on Words[HDU1116]

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. POJ 1386 Play on Words(欧拉图的判断)

    Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11838   Accepted: 4048 De ...

  5. 欧拉通路-Play on Words 分类: POJ 图论 2015-08-06 19:13 4人阅读 评论(0) 收藏

    Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10620 Accepted: 3602 Descri ...

  6. hdu 1116 Play on Words 欧拉路径+并查集

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. Play on Words(有向图欧拉路)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8571   Accepted: 2997 Description Some ...

  8. hdu 1116 Play on Words(欧拉通路)

    Problem Description Some of the secret doors contain a very interesting word puzzle. The team of arc ...

  9. uva 10129 poj 1386 hdu 1116 zoj 2016 play on words

    //本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!! 题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点 ...

随机推荐

  1. CSS学习笔记----CSS3自定义字体图标

    响应式网页字体图标 作者:大漠 日期:2014-01-28 点击:3220 @font-face Responsive 本文由大漠根据Jason的<Responsive Webfont Icon ...

  2. 16.迭代器模式(Iterator Pattern)

    using System; namespace ConsoleApplication9 { class Program { /// <summary> /// 迭代器模式提供了一种方法顺序 ...

  3. Ultra-QuickSort【归并排序典型题目】

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 34470   Accepted: 12382 ...

  4. BI 项目管理之角色和职责

          DW/BI 系统在生命周期中需要许多不同的角色和技能,它们来自业务和技术领域.本文将介绍创建DW/BI 系统所涉及的主要角色.角色和人之间很少是一对一关系.与我们合作的团队小到只有一人,大 ...

  5. Freemarker遍历map

    map的键尽量是字符串或者数字类型: <#if map?exists> <#list map?keys as key> ${key}---${map[key]} </#l ...

  6. CI登录验证

    预先加载数据库操作类和Session类 即在autoload.php中,$autoload['libraries'] = array('database', 'session'); a. 注: 使用s ...

  7. windows phone SDK 8.0 模拟器异常 0x89721800解决办法

    删除 APPDATA\LOCAL\Microsoft\Phone Tools\CoreCon\10.0 从新启动即可!

  8. Eclipse的详细安装步骤

    第一种:这个方法是在线安装的  第二种:下载完整免安装包 首先打开网址:http://www.eclipse.org/ 然后在这里我就选择64位的安装,就以安装安卓开发的举例: 然后下载即可:

  9. 【JSON 注解】JSON循环引用2----JSON注解@JsonIgnoreProperties+JAVA关键字transient+后台对象与JSON数据的格式互相转化

    接着来说这个JSON循环引用的问题: 关于JSON格式的转化,其实关键就是这几个依赖: <!-- json --> <!-- 1号 --> <dependency> ...

  10. js jquery 实现点击按钮后,倒计时60秒才能再次点击发送验证邮件

    <input type="button" id="btn" value="免费获取验证码" /><script type= ...