HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade
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.
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
31.500
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
using namespace std;
//#define LOCAL
struct Node
{
int num;//绿豆数量
int need;//需要猫粮
}t;
int cmp(Node n1,Node n2)//单价从小到大
{
return 1.0*n1.need/n1.num<1.0*n2.need/n2.num;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
int n,m;//猫粮,组数
vector<Node> v;
while(cin>>n>>m&&n!=-)
{
v.clear();
double ans=;
for(int i=;i<m;i++)
cin>>t.num>>t.need,v.push_back(t);
sort(v.begin(),v.end(),cmp);
for(int i=,siz=v.size();i<siz;i++)
{
t=v[i];
if(t.need<=n)ans+=t.num,n-=t.need;
else {ans+=n/(1.0*t.need/t.num);break;}
}
printf("%.3lf\n",ans);
}
return ;
}
HDU 1009 FatMouse' Trade(贪心)的更多相关文章
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDU 1009 FatMouse' Trade(简单贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1009 FatMouse' Trade【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
- HDOJ.1009 FatMouse' Trade (贪心)
FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- 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) ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
随机推荐
- Chapter 21_5 替换
gsub函数的第三个参数不仅是一个字符串,还可以是一个函数或table. 如果是函数,gsub会在每次找到匹配时调用该函数.调用时的参数是捕获到的内容,该函数的返回值作为要替换的字符串. 如果是tab ...
- 敏捷开发(六)- SCRUM全员会议
本文主要是为了检测你对SCRUM 全员会议的了解和使用程度,通过本文你可以检测一下 1.你们的SCRUM 全员会议的过程和步骤 2.SCRUM 全员会议的输出结果 一.会议目的 组成团 ...
- 改造jQuery-Tagit 插件支持中文全角的逗号和空格
jQuery 的 tagit 插件效果还是不错的,今天用到该插件但发现不能自定义标签分隔符,只能是英文半角逗号或空格,于是想改造下 效果: 先研究了一番插件的代码,发现并不能通过插件自身的扩展方法来实 ...
- CodeForces 340E Iahub and Permutations
容斥原理,组合数. 找出有$cnt$个数字还有没放,那么总方案数就是$cnt!$. 总方案数里面包含了正确的和非正确的,我们需要将非正确的删去. 先删去$1$个数字$a[i]=i$的情况,发现会多删, ...
- C#基础--属性
定义一个Book类: namespace ConsoleTest { public class Book { private string _bookIsbn; private string _boo ...
- UIAlerView、UIActionSheet 和UIAlertViewController(点击注销确认按钮实现)
- (IBAction)loginOut:(UIBarButtonItem *)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] ...
- mozilla your firefox profile cannot be loaded. it may be missing or inaccessible
check the permissions ls -l ~/.cache | grep mozilla fix the permissions sudo chown -R $USER:$USER ~/ ...
- chd校内选拔赛题目+题解
题目链接 A. Currency System in Geraldion 有1时,所有大于等于1的数都可由1组成.没有1时,最小不幸的数就是1. #include<iostream> ...
- 杭电OJ--自行车计速器
Biker's Trip Odometer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- NYOJ-914 Youth的最大化(贪心)
Youth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗? ...