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

Author

CHEN, Yue

Source

ZJCPC2004

#include<stdio.h>
#include<algorithm>//sort的头文件
using namespace std;
const int maxn=+;
struct node{
double j,f;
double r;
}a[maxn];
bool cmp(node a,node b)//从大到小排序
{
return a.r>b.r;
}
int main()
{
int m,n,i;
double sum;
while(scanf("%d%d",&m,&n)==&&(m!=-&&n!=-))
{
for(i=;i<n;i++){
scanf("%lf%lf",&a[i].j,&a[i].f);
a[i].r=a[i].j/a[i].f;
}
sort(a,a+n,cmp);
sum=0.0;
for(i=;i<n;i++)
{
if(m>=a[i].f)
{
sum+=a[i].j;
m-=a[i].f;
}
else
{
sum+=(a[i].r)*m;
break;
}
}
printf("%.3lf\n",sum);
}
return ;
}

HDU1009FatMouse' Trade(贪心)的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

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

  2. HDU 1009 FatMouse' Trade(贪心)

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

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

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

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

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

  5. ZOJ FatMouse' Trade 贪心

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

  6. FatMouse' Trade (贪心)

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

  7. SGU 280.Trade centers(贪心)

    SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...

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

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

  9. 20181009noip HZ EZ 两校联考trade(优先队列,贪心)

    题面戳这里 思路: 裸的,贪心... 考场上写了一个数据分治(70ptsDP,30pts线段树优化贪心,GG了后30分) 这道题其实很简单的 我们看图: 我们在A时刻买一个东西,在B时刻卖出去,我们可 ...

随机推荐

  1. POJ3177 Redundant Paths 双连通分量

    Redundant Paths Description In order to get from one of the F (1 <= F <= 5,000) grazing fields ...

  2. USACO 4.1 Beef McNuggets

    Beef McNuggetsHubert Chen Farmer Brown's cows are up in arms, having heard that McDonalds is conside ...

  3. Zabbix-agent使用自带模板监控 MySQL

    1.rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm 2.yum ...

  4. wpf ProgressBar使用

    wpf     progressBar使用起来有些麻烦,直接设置value的值还不行 而是通过委托来执行setValue方法 //Create a Delegate that matches the ...

  5. JAVA上连接ubuntu14.04上的Hbase

    对于新手来说,连接虚拟机上的Hbase有点繁琐,而且网上的配置不太适合初学者,今天我就整理了一下,希望对你们有帮助,第一次发博客. 1.首先去官网下载Hbase的压缩包.我这里用的是1.2.1 htt ...

  6. LeetCode 213. House Robber II

    Note: This is an extension of House Robber. After robbing those houses on that street, the thief has ...

  7. table中td内容过长 省略号显示

    首先设置 css样式: table { table-layout: fixed;} HTML中的table代码: <tr> <th class="col-md-1" ...

  8. 对于行高(line-height)的一些理解

    刚一开始学习这个特性的时候,总是出一些当时看起来很奇怪的问题.现在决定重新整理一下.毕竟使用css,十行揉在一起凑出效果是一种使用,知道为什么会有这种效果也是一种使用.我们需要做一些测试,所以首先需要 ...

  9. macos上安装wget命令

    首先从Apple Store下载Xcode,然后安装Xcode,接着安装Homebrew包管理,类似于Ubuntu下的apt-get: 终端下输入ruby -e "$(curl -fsSL ...

  10. CodeForces 669E Little Artem and Time Machine

    树状数组,$map$. 可以理解为开一个数组$f[i][j]$记录:$i$这个数字在时间$j$的操作情况. 操作$1$:$f[x][t]++$.操作$2$:$f[x][t]--$.操作$3$:$f[x ...