HDU-Fat Mouse' Trade
来源:互联网 发布:vb.net asp网站实例 编辑:程序博客网 时间:2024/05/17 23:14
描述
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.
输入
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.
输出
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.
样例输入
5 37 24 35 220 325 1824 1515 10-1 -1
样例输出
13.33331.500
代码:
#include<stdio.h>#include<algorithm>using namespace std;struct node {int j,f;double pre;}mouse[3001];bool cmp(node a,node b){return a.pre>b.pre;}int main(){int n,m;while(scanf("%d%d",&m,&n)!=EOF&&(n!=-1||m!=-1)){int i;for(i=0;i<n;i++){scanf("%d%d",&mouse[i].j,&mouse[i].f);mouse[i].pre=(double)mouse[i].j/mouse[i].f;}sort(mouse,mouse+n,cmp);//对兑换的性价比排序;double sum=0;for(i=0;i<n;i++){if(m>mouse[i].f)//兑换条件{sum+=mouse[i].j;//累加可以兑换的老鼠食物;m-=mouse[i].f;//兑换后将其从总数中剔除;}else {sum+=mouse[i].pre*m;//m=0;break;}}printf("%.3lf\n",sum);}}
- HDU-Fat Mouse' Trade
- hdu_p1009 Fat Mouse' Trade
- HDOJ 1009 FAT MOUSE TRADE
- hdu 1160 fat mouse speed
- ACM-贪心之Fat Mouse Trade——hdu1009
- fat mouse
- HDOJ1160 Fat Mouse's Speed
- Mouse's trade——贪心
- hdu 2118 Mouse
- HDU 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 - FatMouse' Trade
- HDU-1009 FatMouse' Trade
- hdu 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- HDU 1009 FatMouse' Trade
- c++程序设计——实验1
- 操作系统引论
- Tigase XMPP Server在CentOS部署与配置
- ubuntu下配置tomcat
- 【shell点滴】参数变量
- HDU-Fat Mouse' Trade
- (9-5)创建一个索引库
- 黑马程序员---基础加强:JDK1.5新特性
- 黑马程序员-Java概述
- java连接数据库驱动代码综合共享
- Kinect开发入门
- 黑马程序员---基础加强:注解、代理
- hdu 5228 ZCC loves straight flush && BestCoder Round #41 1001
- Oracle的游标