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. Less 使用指南

    简而言之 Less是为了简化css http://less.bootcss.com/features/ 以上链接是Less中文网站,里面有对Less的详细介绍. 一下写在使用中遇到的问题: 1.下载L ...

  2. python 学习笔记十二 html基础(进阶篇)

    HTML 超级文本标记语言是标准通用标记语言下的一个应用,也是一种规范,一种标准,它通过标记符号来标记要显示的网页中的各个部分.网页文件本身 是一种文本文件,通过在文本文件中添加标记符, 可以告诉浏览 ...

  3. Java类实例化时候的加载顺序

    面试试题中经常考到此问题,现在做进一步的总结: public class Student { public Student(String name){ System.out.println(name) ...

  4. 解决GitLab提交MergeRequest时,提示502 GitLab is not responding.的问题

    最近使用GitLab提交MergeRequest时,提示502 GitLab is not responding. 使用gitlab-ctl tail查看错误信息如下: 2014/10/28 11:5 ...

  5. Response.End()在Webform和ASP.NET MVC下的表现差异

    前几天在博问中看到一个问题--Response.End()后,是否停止执行?MVC与WebForm不一致.看到LZ的描述后,虽然奇怪于为何用Response.End()而不用return方式去控制流程 ...

  6. filter 过滤缓存

    package fifter; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.Filter ...

  7. hdu2825Wireless Password(ac+dp)

    链接 状压dp+ac dp[i+1][next[j]][st|tt]表示第i+1长度结点为next[j]状态为st|tt的时候的ans; dp[i+1][next[j]][st|tt]+=dp[i][ ...

  8. Sealed密封类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; #region 概述 //在 ...

  9. [Excel] Excel固定任意行或者任意列

    固定第一行第一列:点击B2单元格[以B2为中介点,找你冻结部分的中介点!行列的交叉点!] 例如只想固定第一行,那么请选择A2的单元格 为中介点,A3.A4…… 例如只想固定第一列,那么请选择B1的单元 ...

  10. 用sqlplus为oracle创建用户和表空间<转>

    用Oracle10g自带的企业管理器或PL/SQL图形化的方法创建表空间和用户以及分配权限是相对比较简单的,本文要介绍的是另一种方法,使用Oracle 9i所带的命令行工具:SQLPLUS来创建表空间 ...