ACM Greedy Mouse
Greedy Mouse
- 描述
-
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.
- 样例输入
-
- 5 3
- 7 2
- 4 3
- 5 2
- 20 3
- 25 18
- 24 15
- 15 10
- -1 -1
- 5 3
- 样例输出
-
- 13.333
- 31.500
基本的背包问题,用贪心求解
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cstdio>
- #include <utility>
- using namespace std;
- typedef pair<double,double> W;
- bool cmp(const W& a,const W& b){ return a.first > b.first;}
- int main(){
- double m;
- int n;
- while(cin >> m >> n && m!=- && n!=-){
- vector<W> exchange(n);
- for(int i = ; i < n; ++ i){
- double w,f;
- cin >>w >>f;
- exchange[i].first = w/f;
- exchange[i].second = w;
- }
- sort(exchange.begin(),exchange.end(), cmp);
- double res = ;
- for(int i = ; i < n && m; ++i){
- if(m > exchange[i].second/exchange[i].first){
- res += exchange[i].second;
- m -= exchange[i].second/exchange[i].first;
- }else{
- res+=m*exchange[i].first;
- break;
- }
- }
- printf("%0.3f\n",res);
- }
- }
- 13.333
ACM Greedy Mouse的更多相关文章
- POJ1386Play on Words[有向图欧拉路]
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11846 Accepted: 4050 De ...
- SPOJ Play on Words
传送门 WORDS1 - Play on Words #graph-theory #euler-circuit Some of the secret doors contain a very inte ...
- Play on Words[HDU1116]
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- POJ 1386 Play on Words(欧拉图的判断)
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11838 Accepted: 4048 De ...
- 欧拉通路-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 ...
- hdu 1116 Play on Words 欧拉路径+并查集
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Play on Words(有向图欧拉路)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8571 Accepted: 2997 Description Some ...
- hdu 1116 Play on Words(欧拉通路)
Problem Description Some of the secret doors contain a very interesting word puzzle. The team of arc ...
- uva 10129 poj 1386 hdu 1116 zoj 2016 play on words
//本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!! 题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点 ...
随机推荐
- CSS学习笔记----CSS3自定义字体图标
响应式网页字体图标 作者:大漠 日期:2014-01-28 点击:3220 @font-face Responsive 本文由大漠根据Jason的<Responsive Webfont Icon ...
- 16.迭代器模式(Iterator Pattern)
using System; namespace ConsoleApplication9 { class Program { /// <summary> /// 迭代器模式提供了一种方法顺序 ...
- Ultra-QuickSort【归并排序典型题目】
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 34470 Accepted: 12382 ...
- BI 项目管理之角色和职责
DW/BI 系统在生命周期中需要许多不同的角色和技能,它们来自业务和技术领域.本文将介绍创建DW/BI 系统所涉及的主要角色.角色和人之间很少是一对一关系.与我们合作的团队小到只有一人,大 ...
- Freemarker遍历map
map的键尽量是字符串或者数字类型: <#if map?exists> <#list map?keys as key> ${key}---${map[key]} </#l ...
- CI登录验证
预先加载数据库操作类和Session类 即在autoload.php中,$autoload['libraries'] = array('database', 'session'); a. 注: 使用s ...
- windows phone SDK 8.0 模拟器异常 0x89721800解决办法
删除 APPDATA\LOCAL\Microsoft\Phone Tools\CoreCon\10.0 从新启动即可!
- Eclipse的详细安装步骤
第一种:这个方法是在线安装的 第二种:下载完整免安装包 首先打开网址:http://www.eclipse.org/ 然后在这里我就选择64位的安装,就以安装安卓开发的举例: 然后下载即可:
- 【JSON 注解】JSON循环引用2----JSON注解@JsonIgnoreProperties+JAVA关键字transient+后台对象与JSON数据的格式互相转化
接着来说这个JSON循环引用的问题: 关于JSON格式的转化,其实关键就是这几个依赖: <!-- json --> <!-- 1号 --> <dependency> ...
- js jquery 实现点击按钮后,倒计时60秒才能再次点击发送验证邮件
<input type="button" id="btn" value="免费获取验证码" /><script type= ...