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. Java.lang包的接口解读

    Java.lang包中提供了八个接口: 1.Appendable 能够被追加 char 序列和值的对象.如果某个类的实例打算接收来自 Formatter的格式化输出,那么该类必须实现 Appendab ...

  2. 简要谈谈javascript bind 方法

    最近去参加了场面试,跟面试官聊了很多JS基础上的东西,其中有个问题是谈谈对apply.call.bind的理解和区别.顿时一愣,apply.call我知道,经常用的东西,bind是什么鬼!!!好像见过 ...

  3. C#当中利用Attribute实现简易AOP

    首先看一段简单的代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } //来自UI层的调用 ...

  4. js控制iframe的刷新(页面局部刷新)

    今天遇到个问题,后台会员审核之后,页面内的会员审核状态要及时改变,但又不能指望用户手动刷新(用户体验很不好) 如果审核页面和显示审核状态时同在一个html页面的话,那么直接用js改变div内部的文本就 ...

  5. Arcgis for Js实现graphiclayer的空间查询

    本节讲的是Arcgis for Js的针对graphiclayer的空间查询,内容很简单,代码如下: <!DOCTYPE html> <html> <head> & ...

  6. SBT构建工具

    SBT Simple Build Tool. A interactive build tool. install windows可直接到http://www.scala-sbt.org/0.13/do ...

  7. ORM版,学生管理系统02

    学生管理系统 urls.py url(r'^student_list/$',views.student_list,name="student_list"), url(r'^dele ...

  8. [qt][问题记录] 无法定位程序输入点 _ZdaPvj 于动态链接库 libstdc++-6.dll

    无法定位程序输入点 _ZdaPvj 于动态链接库 libstdc++-6.dll 该问题是没有打包库的问题,之所以出现这个问题的是直接用系统自带的命令行使用qt的windeployqt命令导致提供的库 ...

  9. python学习之准备

    快速入门:十分钟学会Pythonhttp://python.jobbole.com/43922/python框架http://www.elias.cn/Python/HomePage#toc14[Py ...

  10. 数据结构(栈&堆 )

    在计算机领域,堆栈是一个不容忽视的概念,堆栈是两种数据结构.堆栈都是一种数据项按序排列的数据结构,只能在一端(称为栈顶(top))对数据项进行插入和删除.在单片机应用中,堆栈是个特殊的存储区,主要功能 ...