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 ...
随机推荐
- <一>获取数据库连接
一.JDBC_通过Driver接口获取数据库连接 1. Driver是一个接口:数据库厂商必须提供实现的接口,可以从其中 获取数据库连接. 2.JDBC URL由三部分组成,各部分用冒号隔开,格式:j ...
- Oracle ITL(Interested Transaction List)理解
ITL(Interested Transaction List) ITL是位于数据块头部的事物槽列表,它是由一系列的ITS(Interested Transaction Slot,事物槽)组成,其初始 ...
- NGUI实现技能CD效果
在NGUI中使用Sprite的遮罩效果可以很轻松的实现技能CD效果. 具体实现步骤: ①新建一个技能图标的Sprite 如图中的Skill001,再在该技能Sprite上添加一个Sprite做遮罩, ...
- SQL语法
full outer--全连.两表相同的组合在一起,A表有,B表没有的数据(显示为null),同样B表有,A表没有的显示为(null) A表 left join B表--左连,以A表为基础,A表的全部 ...
- jcl-over-slf4j log桥接工具简介
ava 界里有许多实现日志功能的工具,最早得到广泛使用的是 log4j,许多应用程序的日志部分都交给了 log4j,不过作为组件开发者,他们希望自己的组件不要紧紧依赖某一个工具,毕竟在同一个时候还有很 ...
- PHP的变量
1.可变变量 一个变量的变量名可以动态地设置和使用.一个普通的变量通过声明来设置,而一个可变变量获取了一个普通变量的值作为这个可变变量的变量名,如下所示: <?php $hi = "h ...
- 安卓中級教程(4):ScrollView與ListView之間的高度問題
在scrollView中加插ListView是一個大難題.其中一個難題是Listview的高度難以計算,輸出效果往往強差人意,就讓我們看看當中的問題 . <LinearLayout xmlns: ...
- ExtJS笔记 Ext.data.Types
This is a static class containing the system-supplied data types which may be given to a Field. Type ...
- nginx中相关配置
#nginx 开启目录浏览 location / { root /data/www/file //指定实际目录绝对路径: autoindex on; //开启目录浏览功能: autoindex_exa ...
- 针对功能权限(url访问)如何避免越权访问
你可以用request获得之前的页面路径:Request.getHeader("Referer");然后你可以判断一下,这个是字符串类型的. 如果是需要登录的,你可以从sessio ...