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) ...
随机推荐
- BeanUtils包的学习
BeanUtils支持八种基本数据类型(int double short char byte float boolean long)的反射,对于日期需要提前注册DateLocalConvert获取转换 ...
- POJ 2488 A Knight's Journey(DFS)
A Knight's Journey Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 34633Accepted: 11815 De ...
- ES6新特性-------解构、参数、模块和记号(续)
六.解构 解构提供了一个方便的地从对象或数组中提取数据的方法,请看下面的例子: //ES6 let [x,y]=[1,2];//x=1,y=2 //ES5 var arr=[1,2]; var x=a ...
- Android SDK更新缓慢或无法更新的解决方法
windows 解决方法就是修改C:\Windows\System32\drivers\etc\hosts文件.添加一行: 74.125.237.1 dl-ssl.google.com l ...
- JavaEE Tutorials (29) - Duke辅导案例研究示例
29.1Duke辅导应用的设计和架构44529.2主界面447 29.2.1主界面中使用的Java持久化API实体447 29.2.2主界面中使用的企业bean448 29.2.3主界面中使用的Web ...
- spring-boot+nginx+tomcat+ssl配置笔记
如果你的tomcat应用需要采用ssl来加强安全性,一种做法是把tomcat配置为支持ssl,另一种做法是用nginx反向代理tomcat,然后把nginx配置为https访问,并且nginx与tom ...
- 百度地图LV1.5实践项目开发工具类bmap.util.jsV1.1
/** * 百度地图使用工具类-v1.5 * * @author boonya * @date 2013-7-7 * @address Chengdu,Sichuan,China * @email b ...
- Kindeditor+web.py+SAE Storage 实现文件上传 - 开源中国社区
Kindeditor+web.py+SAE Storage 实现文件上传 - 开源中国社区 Kindeditor+web.py+SAE Storage 实现文件上传
- NicEdit - WYSIWYG Content Editor, Inline Rich Text Application
NicEdit - WYSIWYG Content Editor, Inline Rich Text Application By calling the nicEditors.allTextarea ...
- ios sourecTree
1, http://www.jianshu.com/p/be9f0484af9d 2, http://blog.csdn.net/viewcode/article/details/42291973