Problem 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 【题意】一只老鼠有n的猫粮,一只猫有m间房,每间房有num的豆需要val的猫粮换取,求最大能换到的豆
【思路】简单的贪心问题
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=+;
int n,m;
struct node
{
double num;
double val;
double p;
}a[N];
bool cmp(node a,node b)
{
return a.p>b.p;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(m==-&&n==-) break;
for(int i=;i<=m;i++)
{
scanf("%lf%lf",&a[i].num,&a[i].val);
a[i].p=1.0*a[i].num/a[i].val; }
sort(a+,a+m+,cmp);
double ans=;
for(int i=;i<=m;i++)
{
if(n==) break; if(a[i].val<=n)
{
n-=a[i].val;
ans+=a[i].num;
}
else
{
ans+=1.0*n*a[i].p;
break;
}
}
printf("%.3lf\n",ans);
}
return ;
}

FatMouse' Trade_贪心的更多相关文章

  1. HDU 1009 FatMouse' Trade(贪心)

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

  2. HDOJ.1009 FatMouse' Trade (贪心)

    FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...

  3. hdoj1009 FatMouse' Trade——贪心算法

    贪心思路:按单位猫粮能兑换到的javaBean从大到小将组合进行排序,总是在当前兑换尽可能多的javabeans 问题描述:点击打开链接 hdoj1009 FatMouse's Trade 源代码: ...

  4. ZOJ FatMouse' Trade 贪心

    得之我幸,不得,我命.仅此而已. 学姐说呀,希望下次看到你的时候依然潇洒如故.(笑~) 我就是这么潇洒~哈哈. 感觉大家比我还紧张~ 我很好的.真的 ------------------------- ...

  5. FatMouse' Trade (贪心)

    #include <iostream> #include <stdio.h> #include <cstring> #include <cmath> # ...

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

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

  7. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

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

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

  9. 九度OJ 1433 FatMouse -- 贪心算法

    题目地址:http://ac.jobdu.com/problem.php?pid=1433 题目描述: FatMouse prepared M pounds of cat food, ready to ...

随机推荐

  1. pickle与shelve

    pickle Example 写入文件 import pickle integers = [1, 2, 3, 4, 5] with open('pickle-example.p', 'wb') as ...

  2. R----plotly包介绍学习

    plotly包:让ggplot2的静态图片变得可交互 Plotly 是个交互式可视化的第三方库,官网提供了Python,R,Matlab,JavaScript,Excel的接口,因此我们可以很方便地在 ...

  3. Unity3D之协程(Coroutines & Yield )

    在Unity中StartCoroutine/yield return这个模式到底是怎么应用的? 比如你要一个方法进行一个比较耗时的复杂运算~同时又想让脚本流畅的进行其他操作而不是卡在那里等该方法执行完 ...

  4. WPF+WEB+WinForm->>表现层共用类

    首先在解决方案里新建一个类库,然后在解决方案里新建三个项目,WPF,WEB,WinForm,但是这三个项目都需要一个计算类进行计算,那么就在新建的类库Calculator里面放一个Calculat.c ...

  5. hdu 5446 Unknown Treasure 卢卡斯+中国剩余定理

    Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  6. Bilinear Filter

    参考资料: 1. 维基百科Biliner Filtering 2. 维基百科Texture Filtering 3.维基百科Bilinear Interpolation 4. 维基百科Bilinear ...

  7. laravel多国语言包

    https://packagist.org/packages/caouecs/laravel-lang 例如安装中文语言包 则下载 zh-CN 拷贝文件到 resouces/lang 下 然后修改co ...

  8. block(闭包)

    使用方式 1定义为类的属性 最后用来发布通知,执行block即可 甚至同时发送数据参数,给方法调用者,这样返回数据比返回值形式,更好, 因为这样传参,不是同步的,而是异步响应式的,更加灵活安全. 2定 ...

  9. python核心编程第六章练习6-15

    转换.(a)给出两个可识别格式的日期,比如MM/DD/YY或者DD/MM/YY格式.计算出两个日期之间的天数.(b)给出一个人的生日,计算此人从出生到现在的天数,包括所有的闰月.(c)还是上面的例子, ...

  10. 【转】selenium之 定位以及切换frame

    转载自:http://www.voidcn.com/blog/huilan_same/article/p-6155896.html 很多人在用selenium定位页面元素的时候会遇到定位不到的问题,明 ...