FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 43381 Accepted Submission(s):
14499
with the cats guarding the warehouse containing his favorite food,
JavaBean.
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.
case begins with a line containing two non-negative integers M and N. Then N
lines follow, each contains two non-negative integers J[i] and F[i]
respectively. The last test case is followed by two -1's. All integers are not
greater than 1000.
number accurate up to 3 decimal places, which is the maximum amount of JavaBeans
that FatMouse can obtain.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;
#define N 1005 struct Trade{
int J, F; //J代表JavaBeans,F代表cat food
double price; //性价比
}trade[N]; int cmp(Trade a,Trade b)
{
return a.price>b.price;
}
int main()
{
double maximum;
int m, n, i;
while(cin>>m>>n)
{
maximum = ;
if(m==- && n==-)
break;
maximum = ;
for(i=; i<n; i++)
{
cin>>trade[i].J>>trade[i].F;
trade[i].price = trade[i].J*1.0/trade[i].F;
}
sort(trade,trade+n,cmp);
for(i=; i<n; i++)
{
if(m == )
break;
else if(trade[i].F<=m)
{
maximum += trade[i].J;
m -= trade[i].F;
}
else
{
maximum += m*trade[i].price;
m = ;
}
}
printf("%.3lf\n",maximum);
}
return ;
}
Hdu 1009 FatMouse' Trade的更多相关文章
-
HDU 1009 FatMouse&#39; Trade(简单贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
-
HDU 1009 FatMouse&#39; Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
-
hdu 1009:FatMouse&#39; Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
-
Hdu 1009 FatMouse&#39; 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&#39; Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
-
Hdu 1009 FatMouse&#39; 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&#39; Trade【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
-
[题解]hdu 1009 FatMouse&#39; Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
-
HDU 1009 FatMouse&#39; Trade肥老鼠的交易(AC代码) 贪心法
题意: 一只老鼠用猫粮来换豆子,每个房间的兑换率不同,所以得尽量从兑换率高的房间先兑换.肥老鼠准备M磅猫粮去跟猫交易,让猫在warehouse中帮他指路,以找到好吃的.warehouse有N个房间,第 ...
随机推荐
-
log4cxx
1.简介 (1)Apache log4cxx当前是由Apache软件基金会进行维护.它是java中著名开源项目Apache log4j在c++中对应的日志框架.它是借助于APR(Apache Port ...
-
如何安装ESXi的补丁
1.进入维护模式 2.通过vSphere Client上传补丁 3.开SSH后使用Putty连接 4.esxcli software vib install -d="/vmfs/volume ...
-
c语言函数传递数组
1.传递数组,打印不出来 #include <stdio.h> void solve() { printf(]); } int main() { int i; ;i<n;i++) { ...
-
【技术贴】解决Program Files文件夹消失
好久不写程序了,今天良心发现,就寻找一下自己是否安装了JDK,习惯性的去C盘的Program Files的文件夹下面去找,次奥,没有这个文件夹.好吧.是在玩我么. 于是 打开cmd 输入如下命令 AT ...
-
每个Linux新手都应该记住的10个基本Linux命令
Linux对我们的生活有着很大的影响.至少,你的安卓手机上面就有Linux内核.然而,头一次入手Linux只会让你觉得不适.因为在Linux上,你通常应该使用终端命令,而不是只要点击启动器图像(就像你 ...
-
VMware workstation转到vsphere解决办法
一.前因 上一篇http://www.cnblogs.com/cuncunjun/p/6611837.html 中提到,我想把本地的vmware workstation的虚拟机拷贝到服务器上,因为鄙人 ...
-
LuceneNet 实现快速大文件大数据查询
做过站内搜索的朋友应该对Lucene.Net不陌生,因为用普通的sql like查询肯定是不行的,太慢了. 首先说明的是--Lucene.Net只是一个全文检索开发包,不是一个成型的搜索引擎, 它的 ...
-
如何自动增加和从代码读取Xcode项目的版本号
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) Xcode项目和版本号相关的有2个地方Version和Buil ...
-
IoT experitment
Abstract: In order to solve the problems of complex experiment management, complicated teaching task ...
-
springboot12-zuul
Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门,提供动态路由,监控,弹性,安全等的边缘服务 所有请求都经过网关(API Gateway)zuul,然后转发到各个子服 ...