hdu 1009 FatMouse' Trade
来源:互联网 发布:望远镜淘宝网 编辑:程序博客网 时间:2024/06/15 08:37
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 53745 Accepted Submission(s): 17970
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.
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猫粮,让你你换鼠粮,怎样换最多,注意,仓库里鼠粮只有j[i],也就是只能换一次,换东西当然靠考虑性价比,相同猫粮换鼠粮多的才划算,也就是就性价比高的开始算,性价比算法就是对应仓库鼠粮比上猫粮,再排序*/
代码如下
#include<iostream>#include<algorithm>#include<cstdio>#define maxn 1000+10using namespace std;struct node{int j; //鼠粮int f; // 猫粮粮double value;//性价比 }; bool rule(node x,node y){return x.value>y.value;}int main(){node stu[maxn];int n,m;while(scanf("%d %d",&m,&n)&&m!=-1&&n!=-1){for(int i=0;i<n;i++) {scanf("%d %d",&stu[i].j,&stu[i].f);stu[i].value=(double)stu[i].j/stu[i].f;}sort(stu,stu+n,rule);double sum=0;for(int i=0;i<n;i++) {if(m>=stu[i].f) sum+=stu[i].j,m-=stu[i].f;else{ sum+=m*stu[i].value; break;}}printf("%.3lf\n",sum);}return 0;}
0 0
- 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
- 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
- HDU 1029 Ignatius and the Princess IV
- 电源管理之——battery选型
- 多线程编程基础知识
- 基于Html5的移动端(APP)开发框架的优缺点
- 第一个mysql存储过程
- hdu 1009 FatMouse' Trade
- RadGridView
- git 使用
- 十大紧缺行业发布,近半工作机会在一线
- 表、栈和队列
- VS中lib和dll
- Client访问控制和Cyrus sasl认证.doc
- 欢迎使用CSDN-markdown编辑器
- 欢迎使用CSDN-markdown编辑器