博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FatMouse' Trade
阅读量:5114 次
发布时间:2019-06-13

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

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 37 24 35 220 325 1824 1515 10-1 -1

Sample Output

13.33331.500 题目意思:大老鼠一共有m磅的猫粮要和n个房间里面的猫做交易来换取他喜欢吃的食物,他不需要和所有的房间都进行交易,他支出F[i],会得到J[i], 问他能得到的最大食物数。 解题思路:这算是我接触到的第一道贪心策略的题目,我用结构体来记录每个房间需要交易的猫粮和能换到的食物,以及兑换比率,贪心策略就是每次选择兑换比率大的来兑换 就能够得到最多兑换食物量。 上代码:
#include
#include
using namespace std;struct food{ int j; int f; double q;};int compare(food a,food b){ if(a.q>b.q) return 1; else return 0;}int main(){ int n,m,i,k,l; double s; struct food a[1000],t; while(scanf("%d%d",&m,&n)!=EOF) { if(m==-1||n==-1) break; for(i=0; i
=a[i].f) { s=s+a[i].j; m=m-a[i].f; } else if(m
=0) { s=s+(m*a[i].q); break; } } printf("%.3lf\n",s); } return 0;}
 

 

 

转载于:https://www.cnblogs.com/wkfvawl/p/8711208.html

你可能感兴趣的文章
jQuery Mobile笔记
查看>>
8、RDD持久化
查看>>
第二次团队冲刺--2
查看>>
查询数据(后台到前台传递数据,显示数据)
查看>>
集群tomcat+apache配置文档
查看>>
VMware Tools安装
查看>>
Linux上架设boost的安装及配置过程
查看>>
[转载]加密算法库Crypto——nodejs中间件系列
查看>>
zoj 2286 Sum of Divisors
查看>>
OO5~7次作业总结
查看>>
如何判断主机是大端还是小端(字节序)
查看>>
Centos7 日志查看工具
查看>>
使用Xshell密钥认证机制远程登录Linux
查看>>
BZOJ2459 : [BeiJing2011]神秘好人
查看>>
OpenCV之响应鼠标(三):响应鼠标信息
查看>>
python7 数据类型的相互转化 字符编码
查看>>
Android 画图之 Matrix(一)
查看>>
List<T>列表通用过滤模块设计
查看>>
【模板】最小生成树
查看>>
设计模式之结构型模式
查看>>