FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36632    Accepted Submission(s): 12064

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
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1050 1051 1052 1007 1049 
 
 
水题,读不懂题意是个坑,英语是个大问题啊……
 
 #include <iostream>
#include <iomanip>
using namespace std; int main()
{
int N,M;
while(cin>>M>>N,M!=- || N!=-){
int J[],F[];
for(int i=;i<=N;i++){
cin>>J[i]>>F[i];
}
//ÅÅÐò
for(int i=;i<=N-;i++)
for(int j=;j<=N-i;j++){
if((double)J[j]/F[j]<(double)J[j+]/F[j+]){
int t;
t=F[j];F[j]=F[j+];F[j+]=t;
t=J[j];J[j]=J[j+];J[j+]=t;
}
}
int fs=,fe=; //¼ÆËã
double res=;
for(int i=;i<=N;i++){
if(M-F[i]>=){
res+=J[i];
M-=F[i];
}
else{
res+=M/(double)F[i]*(double)J[i];
break;
}
}
cout<<setiosflags(ios::fixed);
cout<<setprecision();
cout<<res<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 1009:FatMouse' Trade(贪心)的更多相关文章

  1. HDU 1009 FatMouse' Trade(贪心)

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

  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' Trade(简单贪心)

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

  4. HDU 1009 FatMouse' Trade【贪心】

    解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...

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

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

  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 2016-05-05 23:02 86人阅读 评论(0) 收藏

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

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

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

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

随机推荐

  1. mysql 存储过程中注意的问题

    OPEN cur; REPEAT FETCH cur INTO int_type, int_element_id, int_num, int_user_id; IF NOT _DONE THEN IF ...

  2. Nginx 中 fastcgi_pass 监听端口 unix socket和tcp socket差

    Nginx 中 fastcgi_pass 监听端口 unix socket和tcp socket差别   Nginx连接fastcgi的方式有2种:unix domain socket和TCP,Uni ...

  3. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划)

    题意: 求解最大递增子序列. 例如:3 1 3 2 输入 3  个数 1 3 2 则递增子序列有 {1} {3} {2} {1 3} {1 2} ,故输出子序列的最大和 4 解题思路: x[n](n个 ...

  4. centos7中systemctl命令使用方法和心得体会

    使用linux的同学对service和chkconfig两个命令都不陌生,其重要性不言而喻,那么怎么会突然冒出个systemctl命令呢?其实,为了简化操作,systemctl命令将service和c ...

  5. 利用ps橡皮擦工具快速抠图

    原图 最终效果 1.打开图片,ctrl+j得到图层1,点击红圈处,创建图层2,放于图层1与背景层之间,填充白色作为检查效果和新的背景. 2.按图示给出的参数,用背景橡皮擦在图层1里擦吧,注意擦的时候尽 ...

  6. 解决Jquery对input file控件的onchange事件只生效一次的问题

    如题,解决办法的代码如下: 1. $('#fileId').live('change',function(){ //逻辑添加.... }); 2. $('#fileId').change(functi ...

  7. vsftpd的安装

    好像linux下的服务的配置和文件分布都差不多, 如httpd, vsftpd, named. 都是: 在/etc/???下面进行配置???.conf, 然后在/var/???放置实际要处理的文件/目 ...

  8. lnmp一键安装包删除添加的域名

    lnmp一键安装包删除添加的域名 如果使用lnmp一键安装包/root/vhost.sh 添加的域名可以,可以删除/usr/local/nginx/conf/vhost/要删除的域名.conf 文件, ...

  9. BC.36.Gunner(hash)

    Gunner  Accepts: 391  Submissions: 1397  Time Limit: 8000/4000 MS (Java/Others)  Memory Limit: 65536 ...

  10. Rescue

    1039: Rescue Time Limit: 1 Sec  Memory Limit: 32 MBSubmit: 1320  Solved: 306 Description Angel was c ...