hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36632 Accepted Submission(s): 12064
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.
#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(贪心)的更多相关文章
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDU 1009 FatMouse' Trade(简单贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDU 1009 FatMouse' Trade【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
- HDOJ.1009 FatMouse' Trade (贪心)
FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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 ...
- 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) ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
随机推荐
- mysql 存储过程中注意的问题
OPEN cur; REPEAT FETCH cur INTO int_type, int_element_id, int_num, int_user_id; IF NOT _DONE THEN IF ...
- Nginx 中 fastcgi_pass 监听端口 unix socket和tcp socket差
Nginx 中 fastcgi_pass 监听端口 unix socket和tcp socket差别 Nginx连接fastcgi的方式有2种:unix domain socket和TCP,Uni ...
- 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个 ...
- centos7中systemctl命令使用方法和心得体会
使用linux的同学对service和chkconfig两个命令都不陌生,其重要性不言而喻,那么怎么会突然冒出个systemctl命令呢?其实,为了简化操作,systemctl命令将service和c ...
- 利用ps橡皮擦工具快速抠图
原图 最终效果 1.打开图片,ctrl+j得到图层1,点击红圈处,创建图层2,放于图层1与背景层之间,填充白色作为检查效果和新的背景. 2.按图示给出的参数,用背景橡皮擦在图层1里擦吧,注意擦的时候尽 ...
- 解决Jquery对input file控件的onchange事件只生效一次的问题
如题,解决办法的代码如下: 1. $('#fileId').live('change',function(){ //逻辑添加.... }); 2. $('#fileId').change(functi ...
- vsftpd的安装
好像linux下的服务的配置和文件分布都差不多, 如httpd, vsftpd, named. 都是: 在/etc/???下面进行配置???.conf, 然后在/var/???放置实际要处理的文件/目 ...
- lnmp一键安装包删除添加的域名
lnmp一键安装包删除添加的域名 如果使用lnmp一键安装包/root/vhost.sh 添加的域名可以,可以删除/usr/local/nginx/conf/vhost/要删除的域名.conf 文件, ...
- BC.36.Gunner(hash)
Gunner Accepts: 391 Submissions: 1397 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536 ...
- Rescue
1039: Rescue Time Limit: 1 Sec Memory Limit: 32 MBSubmit: 1320 Solved: 306 Description Angel was c ...