FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 53352    Accepted Submission(s): 17788

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 有m个猫食n个房间,每一个房间都有一个猫把守。每一个房间都有j个你想要的东西,要得到东西。就要给猫猫食
每一个猫都有规定的猫食,你给的猫食所占规定的比例就是你得到东西的比例,球最多能得多少个
简单贪心。排序,求值
2015,7,20
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node{
int j,f;
double v;
}a[1100];
bool cmp(node x,node y){
return x.v<y.v;
}
int main(){
int m,n,i;
while(~scanf("%d%d",&m,&n),!(m==-1&&n==-1)){
for(i=0;i<n;i++){
scanf("%d%d",&a[i].j,&a[i].f);
a[i].v=a[i].f*1.0/a[i].j;
}
sort(a,a+n,cmp);
double sum=0;
for(i=0;i<n;i++){
if(m>=a[i].f){
sum+=a[i].j;
m-=a[i].f;
}
else{
double c;
c=m*1.0/a[i].f;
sum+=a[i].j*c;
break;
}
}
printf("%.3lf\n",sum);
}
return 0;
}

hdu 1009 FatMouse&#39; Trade的更多相关文章

  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&#39; Trade(简单贪心)

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

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

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

  5. Hdu 1009 FatMouse' Trade

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

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

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

  7. 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) ...

  8. FatMouse&#39; Trade(杭电1009)

    FatMouse' Trade Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  9. HDU 1009 FatMouse' Trade(贪心)

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

随机推荐

  1. Laravel 的 API 认证系统 Passport 三部曲(二、passport的具体使用)

    GQ1994 关注 2018.04.20 09:31 字数 1152 阅读 1316评论 0喜欢 1 参考链接 Laravel 的 API 认证系统 Passport 三部曲(一.passport安装 ...

  2. php+nginx 限制上传文件大小

    问题:在后台上传8M大小的图片,上传不成功 nginx返回413,如下图所示: 分析:nginx配置文件或者php中,可上传的大小设置太小了 解决办法------检查nginx和php的配置文件里面的 ...

  3. 08C#事件

    C#事件 1.2      事件 事件是C#语言内置的语法,可以定义和处理事件,为使用组件编程提供了良好的基础. 1.16.1       事件驱动 Windows操作系统把用户的动作都看作消息,C# ...

  4. 「 HDU 1978 」 How many ways

    # 解题思路 记忆化搜索 一个点可以跳到的点,取决于它现在的能量.而且有一个显而易见的性质就是一条可行路径的终点和起点的横坐标之差加上纵坐标之差肯定小于等于起点的能量. 因为跳到一个点之后,能量和之前 ...

  5. HDU - 2612 Find a way(BFS搜索)

    题目: 链接 思路: 用BFS分别以‘Y’和‘M’的位置为起点进行两次搜索,并把这两次的搜索结果在一个二维数组中保存下来,在对地图遍历遇到‘@’更行最小值. PS: 如果用‘Y’和‘M’点分别去搜每个 ...

  6. Python 绑定方法与非绑定方法

    用到的: import uuid  --------------  uuid是128位的全局唯一标识符, 通常用32位的一个字符串的形式来表现 uuid.uuid1()  -------------  ...

  7. Vue实例方法之事件的实现

    开始 这段时间一直在看vue的源码,源码非常多和杂,所以自己结合资料和理解理出了一个主线,然后根据主线去剥离其他的一些知识点,然后将各个知识点逐一学习.这里主要是分析的Vue事件处理的实现. 正文 一 ...

  8. Adversarial Auto-Encoders

    目录 Another Approach: q(z)->p(z) Intuitively comprehend KL(p|q) Minimize KL Divergence How to comp ...

  9. C++解决大数组问题

    今天写一个C++小程序,竟然出现:"VS 未经处理的异常: 0xC00000FD: Stack overflow" 查了一下,普通数组变量是在堆栈中保存的,而堆栈空间有限,故出此错 ...

  10. C++动态申请内存 new T()与new T[]的区别

    new与delete 我们知道,new和delete运算符是用于动态分配和撤销内存的运算符. new的用法 开辟单变量地址空间: i. 如 new int ; 指开辟一个存放数组的存储空间,返回一个指 ...