FatMouse' Trade(Hdu 1009)
Description
FatMouse prepared M pounds of cat food, ready to trade 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.
Input
The input consists of multiple test cases. Each test 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.
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
Sample Input
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
13.333
31.500
题解:贪心求解,每一次选择性价比最高的那一个;
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct app
{
double a;
double b;
double p;
};
bool cmp(struct app a,struct app b)
{
return a.p>b.p;
}
int main()
{
int p,i,j,m,u;
double a,k,pp;
struct app b[];
for(;scanf("%d%d",&p,&m)!=-;)
{
if(p==-&&m==-)
break;
for(i=;i<m;i++)
{
scanf("%lf%lf",&b[i].a,&b[i].b);
b[i].p=b[i].a/b[i].b;
}
sort(b,b+m,cmp);
u=;pp=0.0;
for(i=;i<m;i++)
{
pp+=b[i].a;
u+=b[i].b;
if(u>p)
{
pp=(pp-b[i].a)+(p-u+b[i].b)*b[i].p;
break;
}
}
printf("%.3lf\n",pp);
}
return ;
}
FatMouse' Trade(Hdu 1009)的更多相关文章
- 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)T ...
- 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) ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- Hdu 1009 FatMouse' 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' Trade(简单贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs
A. Dasha and Stairs time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- 条款10:让operator=返回一个reference to *this
例如对象x,y,z.要实现连锁赋值(假设operator=已经重载过了):x = y = z,那么operator=则必须返回一个*this. 注意这个条款不仅仅适合于operator=,对于oper ...
- 学习Java有没有什么捷径?
很多网友咨询学习Java有没有什么捷径,我说“ 无他,唯手熟尔 ”.但是愿意将一些经验写出来,以便后来者少走弯路,帮助别人是最大的快乐嘛! 要想学好Java,首先要知道Java的大致分类. 我们知道, ...
- 关于quartus工程添加文件的说明
quartus工程中要添加bsf文件的话需要将源文件也一同添加进来,添加ip核需要添加qip文件,时序约束文件只有添加到工程中才有效果,而timequest分析时需要制定约束文件.
- Oracle数据文件和临时文件的管理
一.数据文件概述在Oracle数据库中,SYSTEM和SYSAUX表空间至少需要包含一个数据文件,此外还将包含多个其他表空间及与其相关的数据文件和临时文件.Oracle的数据文件和临时文件是操作系统文 ...
- wordpress改不了固定连接的解决办法
经常遇到更改了固定连接刷新没效果>>>>>>>废话不多说直接上步骤,有图有真相. 1,ftp删除根目录的这个文件夹 2,进入wp后台设置-固定连接—自定义结构 ...
- Mysql ERROR 1032 (HY000): Can't find record in TABLE
最近用Mysql出现一个很奇怪的问题. 用SELECT * FROM `v_vod` ORDER BY vod_addtime desc LIMIT 0,18查询得到1个错误 ERROR 1032 ( ...
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
http://www.jb51.net/article/58843.htm 一.安装Email发送程序 复制代码 代码如下: yum install sendmail mutt 二.安装FTP客户端程 ...
- poj 3590 The shuffle Problem——DP+置换
题目:http://poj.org/problem?id=3590 bzoj 1025 的弱化版.大概一样的 dp . 输出方案的时候小的环靠前.不用担心 dp 时用 > 还是 >= 来转 ...
- AGC006 C Rabbit Exercise——思路(置换)
题目:https://agc006.contest.atcoder.jp/tasks/agc006_c 选了 i 位置后 x[ i ] = x[ i-1 ] + x[ i+1 ] - x[ i ] . ...