Hdu 1009 FatMouse' Trade
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' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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) ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- 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) ...
- FatMouse' Trade(杭电1009)
FatMouse' Trade Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
随机推荐
- windows下调试virtualbox的虚拟机串口
1.我不知道其他人是怎么实现的,我是这么实现的. 2.下载一个叫做VSPD的软件,其作用是在windosw上虚拟几个串口出来. 下载完了安装,安装完了注册,如果不是花钱买来的,那就自己想办法注册吧.我 ...
- OpenGL光照和颜色
OpenGL光照和颜色 转自:http://www.cnblogs.com/kekec/archive/2011/08/16/2140789.html OpenGL场景中模型颜色的产生,大致为如下的流 ...
- dedecms 时间标签strftime和MyDate
先说下内容页样式: 日期:{field:pubdate function=strftime('m-d',@me)/} 01-01 日期:{field:pubdate function=strftime ...
- Java虚拟机各内存区域的位置及功能的介绍
Java虚拟机运行时数据区: 相关区域介绍: 程序计数器: 功能:当前线程所执行字节码的行号指示器.若是Java方法记录指令地址,若为Native方法,则不记录 隔离性:线程隔离 Error:无 Ja ...
- 大数据技术Hadoop入门理论系列之一----hadoop生态圈介绍
Technorati 标记: hadoop,生态圈,ecosystem,yarn,spark,入门 1. hadoop 生态概况 Hadoop是一个由Apache基金会所开发的分布式系统基础架构. 用 ...
- 【emWin】例程三:显示方向的切换
实验指导书及代码包下载: http://pan.baidu.com/s/1pK9o0xP
- 玩转 H5 下拉上滑动效
按照上面的技术方案实施,具体过程为: 禁用页面顶部下拉事件 ------> 将页面的主体内容用一个DIV容器包含起来,同时复制需要放大处理的内容节点至主体内容之外 ------> 绑 ...
- Myeclipse java程序中运行图片无法加载并且乱码
Windows---prefrence--workspace--text file encoding亲测有效
- Composer 学习笔记
Composer 是 PHP 的一个依赖管理工具(据说是最优秀的).它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们.目前很多项目以Composer 作为依赖管理工具,目前正在学习yii2 ...
- 如何解决Visual Studio调试Debug很卡很慢
http://brightguo.com/make-debugging-faster-with-visual-studio/ Have you ever been frustrated by slow ...