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. TortoiseSVN安装使用

    TortoiseSVN是windows平台下Subversion的免费开源客户端. 一般我们都是先讲讲服务器的配置,然后再讲客户端的使用,但是在TortoiseSVN上,却可以反过来.因为,如果你的要 ...

  2. python学习之if语句

    1.if条件表达式判断 ##判断条件是true or false var1=10 if var1: print("true") print(var1) else: print(&q ...

  3. CSS 盒子模型概述

    一.简介   CSS 盒子模型(元素框)由元素内容(content).内边距(padding).边框(border).外边距(margin)组成.     盒子模型,最里面的部分是实际内容:直接包围内 ...

  4. GMF:如何让网格显示在background,而不是foreground

    前言 很久没写文章了,准备写一系列关于Eclipse RCP /Plugin的文章. 这些文章都是trouble shooting性质的,不准备写的很细,当你碰到这样的问题,google到时,能帮你把 ...

  5. hadoop2.0初识1.1

    1.伪分布式hdfs文件系统的搭建(单节点文件系统) 1.1.根据上节的讲解,配置主机映射.jdk和解压hadoop压缩包 1.2.配置namenode 在/opt/modules/hadoop-2. ...

  6. JDBC读取新插入Oracle数据库Sequence值的5种方法

    Oracle的sequence实现非常灵活,所以也带来一些易用性问题,如何取到新插入记录生成的sequence值与其它数据库有较大差别,本文详国介绍了5种实现读取新插入记录sequence值的方法. ...

  7. HQL 参数绑定、唯一结果、分页、投影总结(上)

    我们先总结一下HQL语句常用语法: from子句:; select子句:用于选取对象和属性; where子句:用于表达查询语句的限制条件; 使用表达式:一般用在where子句中; order by子句 ...

  8. <开心一笑> 前端工程师你们伤不起!

    前端工程师你们伤不起!! 来自: 刻铭 2011-03-11 14:09:53 前端工程师伤不起  老子几年前进了互联网圈!!!!!!!成了前端工程师,名字是不是很拉风,有木有!!!!!!!!  尼玛 ...

  9. js中attr 与find 获取属性值,

    一.attr的用法 1. attr(属性名)        //获取属性的值(取得第一个匹配元素的属性值.通过这个方法可以方便地从第一个匹配元素中获取一个属性的值.如果元素没有相应属性,则返回 und ...

  10. PHP 扩展开发小结

    1. 变量操作(常量) 设置变量 ZVAL_*系列函数; 例: zval t; ZVAL_STRING(t,"10",2); 获取变量 Z_* 系列函数 获取变量指针 Z_*_P ...