【HDU 1009】FatMouse' Trade
Description
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.
Input
Output
Sample Input
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,u;
double m,ans;
struct room
{
double j,f,p;
} r[];
int cmp(room a,room b)
{
return a.p>b.p;
}
int main()
{
while(scanf("%lf%d",&m,&n)&&n!=-&&m!=-)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&r[i].j,&r[i].f),
r[i].p=r[i].j/r[i].f;
sort(r,r+n,cmp);
u=ans=;
while(m&&u<n)
{
if(r[u].f>m) ans+=m*r[u].p,m=;
//剩下的猫粮不够把这个房间的咖啡豆换过来,那就能换多少换多少
else ans+=r[u].j,m-=r[u].f;
//够的话,这间房子全部咖啡豆换过来
u++;
}
// while(m>=r[u].f&&u<n) //换种写法
// {
// ans+=r[u].j;
// m-=r[u].f;
// u++;
// }
// if(u!=n) ans+=m*r[u].p;
printf("%.3lf\n",ans); }
return ;
}
【HDU 1009】FatMouse' Trade的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDOJ 1009】 CRB and String
[HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- HDU 1009:FatMouse' Trade(简单贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
随机推荐
- JavaScript Promise API
同步编程通常来说易于调试和维护,然而,异步编程通常能获得更好的性能和更大的灵活性.异步的最大特点是无需等待."Promises"渐渐成为JavaScript里最重要的一部分,大量的 ...
- java 20 - 9 带有缓冲区的字节输出流和字节输入流
由之前字节输入的两个方式,我们可以发现,通过定义数组读取数组的方式比一个个字节读取的方式快得多. 所以,java就专门提供了带有缓冲区的字节类: 缓冲区类(高效类) 写数据:BufferedOutpu ...
- BZOJ 3572: [Hnoi2014]世界树
BZOJ 3572: [Hnoi2014]世界树 标签(空格分隔): OI-BZOJ OI-虚数 OI-树形dp OI-倍增 Time Limit: 20 Sec Memory Limit: 512 ...
- drbd初探及Heartbeat+DRBD+MySQL
1,drbd快速入门 http://www.mingxiao.info/article/?id=39#__RefHeading___Toc1114_501652171 2.Heartbeat+DRBD ...
- Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- P2P NAT检测和穿越方式
一. NAT类型 本文转自:http://www.cnblogs.com/hummersofdie/archive/2013/05/21/3090163.html 1.基本的NAT类型:只 ...
- 为什么需要DTO(数据传输对象)
DTO即数据传输对象.之前不明白有些框架中为什么要专门定义DTO来绑定表现层中的数据,为什么不能直接用实体模型呢,有了DTO同时还要维护DTO与Model之间的映射关系,多麻烦. 然后看了这篇文章中的 ...
- char,string和CString转换
&1 string->char string str0 = "sophia is a good girl."; const char *str1 = str0.c_s ...
- 将Axure用于需求分析工具
http://www.cnblogs.com/hnlong1/p/4113517.html?utm_source=tuicool 今年以来开始接触需求分析工作,uml是必用的建模语言. 一开始是使用最 ...
- 用python简单处理图片(2):图像通道\几何变换\裁剪
一.图像通道 1.彩色图像转灰度图 from PIL import Image import matplotlib.pyplot as plt img=Image.open('d:/ex.jpg') ...