博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
贪心 --- 模板题
阅读量:6919 次
发布时间:2019-06-27

本文共 2029 字,大约阅读时间需要 6 分钟。

FatMouse' Trade

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

Total Submission(s): 41006    Accepted Submission(s): 13575

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

【题目来源】

【题目大意】

jack有M磅猫食,他想用这些猫食来换他最喜爱的javabeans,在他面前有n个房间,每个房间上表明了:J颗豆可以用F磅猫食来换取。

让你选择最优的方案换取最多的豆。

【题目分析】

贪心的水题,先排序,然后就按顺序选,直至将所有的猫食都换光。

 

#include
#include
using namespace std;struct Node{ int a,b; double c;};Node node[1010];bool cmp(Node a,Node b){ return a.c>b.c;}int main(){ int n,m; while(scanf("%d%d",&n,&m),n!=-1&&m!=-1) { for(int i=0;i
node[i].b) { sum+=node[i].a; n-=node[i].b; } else { sum+=n*node[i].c; break; } } } printf("%.3lf\n",sum); } return 0;}

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/crazyacking/p/3753688.html

你可能感兴趣的文章
关于我的第一个网站www.webtv520.com随笔
查看>>
组播实验
查看>>
空指针和野指针
查看>>
VMware虚拟机桥接方式与真实主机共享上网
查看>>
如何解决SVN Commit failed (details follow): Access denied
查看>>
最新LAMP×××网站平台PHP5.5.1 + Apache2.4.6 + mysql5.6.12
查看>>
看《中国好声音》,学职场生存铁律!
查看>>
ligerFilter.js每次打开绑定不同字段列表
查看>>
ISCSI服务的配置与管理
查看>>
greenplumn----------单机2segment安装
查看>>
第八单元系统服务的控制
查看>>
ansible编写hadoop群集
查看>>
linux云自动化运维基础知识1
查看>>
ghost系统后变成C盘了别的分区的文件怎样找到
查看>>
navicat 连接阿里云RDS的设置
查看>>
CentOS7 搭建 禅道项目管理服务
查看>>
AlphaGo Zero到底是怎么学习成为了无敌的存在?
查看>>
给人工智能「好奇心」会变成什么样?答案不出所料
查看>>
在linux下安装软件
查看>>
Java的新项目学成在线笔记-day4(六)
查看>>