FatMouse' Trade(hdoj1009)
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<stdio.h>/**此题有很多边缘数据没有想到,或者压根就没有去想/
#include<algorithm>
using namespace std;
typedef struct
{
double x,y;/*数据类型错点*/
double z;
}node;
int cmp(node p,node q)
{
return p.z>=q.z;
}
node a[];
int main()
{
double M;
int N;
while(~scanf("%lf%d",&M,&N))
{
int i,j;
double max=,shen=M;
if(M==-&&N==-)
break;
if(N==)/*room为0情况*/
{
printf("0.000\n");
continue;
}
else
{
for(i=;i<N;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].z=a[i].x/a[i].y;
}
sort(a,a+N,cmp);
/*for(i=0;i<N;i++)
printf("%d %d %lf\n",a[i].x,a[i].y,a[i].z);*/
for(i=;;i++)
{
if(shen>a[i].y)
{
max+=a[i].x;
shen=shen-a[i].y;
}
else if(shen==a[i].y)/*可能漏掉,因为存在y=0情况,此情况不能和else并在一起,看了讨论组才知道的*/
{
max+=a[i].x;
shen=shen-a[i].y;
}
else
{
max+=(shen/a[i].y)*a[i].x;
break;
}
}
}
printf("%.3lf\n",max);
}
}
FatMouse' Trade(hdoj1009)的更多相关文章
- 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 (贪心)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 题目大意:肥鼠准备了 磅的猫粮,准备和看管仓库的猫交易,仓库里装有他最喜爱的食物 豆.仓库有 个 ...
- 杭电 1009 FatMouse' Trade (贪心)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- 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 ...
- FatMouse' Trade(杭电ACM---1009)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- [题解]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 (贪心算法)
题意:就是老鼠要用猫粮换粮食,第i个房间一些东西,要用东西去换,可以不全换.问给定的猫粮最多能换多少粮食. 析:贪心算法.我们先算出来每个房间物品的平均价格是多少,肯定越低越好,并且如果能全换就全换, ...
- HDU 1009:FatMouse' Trade(简单贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 微信订阅号开发之token验证后,自动回复消息功能做好,发送消息没有返回
相信很多人会跟我一样,token验证之后,发送消息给订阅号,没有消息返回. 以下,说一下我辛苦调试得到的解决办法: 首先,token验证: 自己写的token一直验证失败,找了好久,没有发现bug.实 ...
- flash播放器遮挡页面中元素问题解决
今天在做一个包含Flash播放器的页面弹出效果时发现Flash播放器总是跑到页面最上层,发现这个问题与Flash的”wmode”属性有关,至于该元素详细此处不做记录,解决办法如下: IE:加入参数:& ...
- 【转】生产环境MySQL Server核心参数的配置
⑴ lower_case_table_names ● 推荐理由 GNU/Linux 平台,对数据库.表.存储过程等对象名称大小 ...
- python - list, cllections模块的deque对象
list.count() list.pop()/list.pop(i) list.insert(i,element) list.sort()和sorted(list) list.reverse()和r ...
- HDU 2266 How Many Equations Can You Find(DFS)
How Many Equations Can You Find Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- Primo Ramdisk配置教程
首先感谢xiaohu在太平洋电脑网上发表的“将内存当硬盘用!Primo Ramdisk图文教程”,本文主要是将其图文整理了一下,以方便以后使用. 原文地址:http://fashion.pconlin ...
- atoi 和itoa用法
1.itoa 在linux下没有itoa这个函数 原型:char *itoa(int value,char *string,int radix) 用法 ...
- bzoj1632 [Usaco2007 Feb]Lilypad Pond
Description Farmer John 建造了一个美丽的池塘,用于让他的牛们审美和锻炼.这个长方形的池子被分割成了 M 行和 N 列( 1 ≤ M ≤ 30 ; 1 ≤ N ≤ 30 ) 正方 ...
- http://bassistance.de/jquery-plugins/
http://bassistance.de/jquery-plugins/ Query插件:手风琴 jQuery插件:自动完成 jQuery插件:留言 jQuery插件:密码验证 jQuery插件:P ...
- windows 基于命令行制作vhd虚拟磁盘
什么是VHD? VHD是Virtual Hard Disk的简称,就是虚拟硬盘,就是能把VHD文件直接虚拟成一个硬盘,在其中能像真实硬盘一样操作,读取.写入.创建分区.格式化.如果你用过虚拟机,就会知 ...