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) ...
随机推荐
- css: 基础一
1.display有哪些值?说明他们的作用 @1.block:设定元素为块级元素,占据一整行,可设置宽高. @2.inline-block: 设定元素行内块元素,可设置宽高,一行能显示多个. @3.i ...
- 剑指offer--31.二叉树中和为某一值的路径
深度优先搜索 --------------------------------------------------------------------------------------------- ...
- Celery分布式应用
最近有应用需要部署到不同的服务器上运行,但是有没有PBS这样的调度系统,就想起来Python的调度神器 Celery.现在针对我的实际应用做一些记录. 1. 安装 因为我并不注重结果而是把命令拿到不同 ...
- warning MSB8004: Output Directory does not end with a trailing slash.
当在VC里编译时,发现这个警告,就是说设置的目录参数不是以反斜杠结束的目录名称,如下: 1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V ...
- Linux部分常用命令学习(一)
什么是linux命令? 是一个可执行程序,就像我们所看到的位于目录/usr/bin 中的文件一样. 属于这一类的程序,可以编译成二进制文件,诸如用 C 和 C++语言写成的程序, 也可以是由脚本语言写 ...
- 洛谷P2835 刻录光盘
传送门 题目大意:有光盘可以传着看,问最少从哪几个人分发,能全部传一遍. 题解:缩点后求入度为0的点的个数 代码: #include<iostream> #include<cstdi ...
- 监听文本框输入oninput和onpropertychange事件
前端页面开发的很多情况下都需要实时监听文本框输入,比如腾讯微博编写140字的微博时输入框动态显示还可以输入的字数.过去一般都使用onchange/onkeyup/onkeypress/onkeydow ...
- kafka ksql && docker 安装试用
备注: 使用docker 模式进行安装 1. 准备docker 环境(需要docker-compose) docker 的安装不需要进行多描述了,直接yum 或者源码编译也可以 ...
- OpenWRT mt7620n 系统升级引起的问题
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qianguozheng/article/details/27237175 OpenWRT系统升级採用 ...
- Android 杂记
Android Studio 报错:sdk location should not contain whitespace as this can cause problems with the ndk ...