HDU 1009 FatMouse' Trade题解
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/。未经本作者同意不得转载。 https://blog.csdn.net/kenden23/article/details/31418535
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.
integers are not greater than 1000.
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
31.500
贪心法水题,
个人认为这句话难理解:he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food
这样表达能够购买几分之几的。
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct twoInts
{
int j, f;
bool operator<(const twoInts two) const
{
double a = (double)j / (double)f;
double b = (double)two.j / (double)two.f;
return a > b;
}
};
int main()
{
int M, N;
while (scanf("%d %d", &M, &N) && -1 != M)
{
vector<twoInts> vt(N);
for (int i = 0; i < N; i++)
{
scanf("%d", &vt[i].j);
scanf("%d", &vt[i].f);
}
sort(vt.begin(), vt.end());
double maxBean = 0.0;
for (int i = 0; i < N; i++)
{
if (M >= vt[i].f)
{
maxBean += vt[i].j;
M -= vt[i].f;
}
else
{
maxBean += (double)vt[i].j * M / (double)vt[i].f;
break;
}
}
printf("%.3lf\n", maxBean);
}
return 0;
}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(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- 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【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
随机推荐
- Mixly-指令
串口: 向串口监视器输出数据 十进制 Serial.println(ir_item,HEX); 向串口监视器输出数据---十六进制 通信: 接收11脚的红外信号,把接收到的数据 ...
- 对async/await的研究
1. 作为一个关键字放到函数前面,用于表示函数是一个异步函数,因为async就是异步的意思, 异步函数也就意味着该函数的执行不会阻塞后面代码的执行. 写一个async 函数 async functio ...
- webpack中require.context 用法
1.require.context(directory, useSubdirectories = false, regExp = /^\.\//) Examples: require.context( ...
- 无线网络中的MIMO与OFDM技术原理分析
无线网络中的MIMO与OFDM技术原理分析CNET中国·ZOL 07年08月14日 [原创] 作者: 中关村在线 张伟 从最早的红外线技术到目前被寄予重望的WIFI,无线技术的进步推动我们的网络一步步 ...
- webstorm 点击右上角运行run 启动vue项目
点击右上角框 -> 编辑结构 点击加号 新增一个npm项目 前提:node环境已经安装完成,npm包管理器 1.进行定位到项目的路径2.安装依赖包,npm install3.启动服务,npm r ...
- BZOJ 3887: [Usaco2015 Jan]Grass Cownoisseur tarjan + spfa
Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) ...
- POJ 2391 Ombrophobic Bovines ( 经典最大流 && Floyd && 二分 && 拆点建图)
题意 : 给出一些牛棚,每个牛棚都原本都有一些牛但是每个牛棚可以容纳的牛都是有限的,现在给出一些路与路的花费和牛棚拥有的牛和可以容纳牛的数量,要求最短能在多少时间内使得每头牛都有安身的牛棚.( 这里注 ...
- 【PowerOJ1754&网络流24题】负载平衡问题(费用流)
题意: 思路: [问题分析] 转化为供求平衡问题,用最小费用最大流解决. [建模方法] 首先求出所有仓库存货量平均值,设第i个仓库的盈余量为A[i],A[i] = 第i个仓库原有存货量 - 平均存货量 ...
- 【BZOJ1563】诗人小G(决策单调性DP)
题意:给定N,L,P,求f[N] sum[i]递增,L<=3e6,P<=10 思路:四边形不等式的证明见https://www.byvoid.com/zhs/blog/noi-2009-p ...
- 180128-----Java面试题
1 不用第三个变量,交换两个的值 a=1;b=2;a=a+b;b=a-b;a=a-b; 2 Java动态代理用什么实现? 反射