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 - 样例输出
-
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);
}
}
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个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点 ...
随机推荐
- php 投票系统练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 使用HttpWebRequest发送自定义POST请求
平时用浏览器看网页的时候,点击一下submit按钮的时候其实就是给服务器发送了一个POST请求.但是如何在自己的C#程序里面实现类似的功能呢?本文给出了一个简单的范例,可以实现类似的和web serv ...
- acpi参考网站
1.acpi官网: http://www.acpi.info/
- Delphi线程基础知识
参考http://blog.chinaunix.net/uid-10535208-id-2949323.html 一.概述 Delphi提供了好几种对象以方便进行多线程编程.多线程应用程序有以下几方面 ...
- 【翻译二十一】java-并发之分拆和合并
Fork/Join This section was updated to reflect features and conventions of the upcoming Java SE 8 rel ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- [Nodejs]十分钟快速编写简单静态文件服务器
学了几天Nodejs 后我又干上了前端的活.这次遇到的问题是,我想在不同的设备上方便的查看我编写的网页,很自然的就想到要是能在本地搭建一个简单的http服务器的话,那局域网内的所有设备都可以访问了,这 ...
- GMap.Net开发之在地图上添加多边形
上一篇介绍了在GMap上添加自定义标签(GMapMarker),这篇介绍在GMap上添加多边形(GMapPolyogn),并且介绍如何在地图上画任意的多边形. 如果已经知道了多边形的各个点的位置,就可 ...
- android studio常见错误
1.Failed to import new Gradle project: Could not install Gradle distribution from'http://services.gr ...