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)的更多相关文章

  1. HDU 1009 FatMouse' Trade(简单贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  2. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  3. Hdu 1009 FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. hdu 1009:FatMouse' Trade(贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. 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) ...

  6. HDU 1009 FatMouse' Trade(贪心)

    FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...

  7. 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 ...

  8. HDU 1009:FatMouse&#39; Trade(简单贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1009 FatMouse&#39; Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. Ceph与OpenStack整合(仅为云主机提供云盘功能)

    1. Ceph与OpenStack整合(仅为云主机提供云盘功能) 创建: linhaifeng,最新修改: 大约1分钟以前 ceph ceph osd pool create volumes 128 ...

  2. 【python】利用h5py存储数据

    两类容器:group & dataset group类似文件夹,字典. dataset是数据集,类似数组 支持更多的对外透明的存储特征,数据压缩,误差检测,分块传输 group下面可以是gro ...

  3. [置顶] C语言学习入门

    编译文件:cc -c one.c two.c  生成.o目标文件 链接文件:cc one.o two.o     默认生成 a.out 执行文件 指定生成的可执行文件名   cc -o one one ...

  4. 说说geotools中坐标转换那点事

    概述: 本文说说geotools中坐标转换的那点事情,以WGS84和web墨卡托相互转换为例. 效果: 转换前 转换后 单个Geometry转换 实现代码: package com.lzugis.ge ...

  5. 7.usr下重要目录和文件详解

    1./usr下重要目录和文件详解: /usr(存放用户安装的应用软件目录,如MySQL,Apache,这是一个非常重要的目录,类似于Windows下的Program Files目录,用户的很多应用程序 ...

  6. SSH实现远程控制

    SSH(Secure Shell)是一种能够提供安全远程登录会话的协议,使用ssh可以在远程linux中执行命令. sshd服务提供两种安全验证的方法: (1)基于口令的安全验证:经过验证帐号与密码即 ...

  7. 浅析Python中bytes和str区别

    本博转载自:Chown-Jane-Y的浅析Python3中的bytes和str类型 Python 3最重要的新特性之一是对字符串和二进制数据流做了明确的区分.文本总是Unicode,由str类型表示, ...

  8. Spring、Spring MVC、Struts2优缺点整理

    Spring 及其优点 大部分项目都少不了Spring的身影,为什么大家对他如此青睐,而且对他的追捧丝毫没有减退之势呢 Spring是什么: Spring是一个轻量级的DI和AOP容器框架. 说它轻量 ...

  9. AVAWEB学习笔记 ---- 系列文章

    [JAVAWEB学习笔记]网上商城实战5:后台的功能模块 [JAVAWEB学习笔记]网上商城实战4:订单模块 [JAVAWEB学习笔记]网上商城实战3:购物模块和订单模块 [JAVAWEB学习笔记]网 ...

  10. hbase filter 简介

    一.基本介绍 1.FilterList代表一个过滤器列表 FilterList.Operator.MUST_PASS_ALL --> 取交集 相当一and操作 FilterList.Operat ...