FatMouse' Trade -HZNU寒假集训
FatMouse' Trade
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
题解:我建立了一个结构体,然后将食物价值用r表示,然后把结构体排序,依次从最大的开始递减,可以保证价值最大。
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
struct food
{
double j;
double f;
double r;
}fo[];
bool compare(food a,food b)
{
return a.r>b.r;
}
int main()
{
int m,n;
while(scanf("%d %d",&m,&n),m!=-,n!=-)
{
for(int i=;i<n;i++)
{
scanf("%lf %lf",&fo[i].j,&fo[i].f);
fo[i].r=fo[i].j/fo[i].f;
}
sort(fo,fo+n,compare);
double ans=;
for(int i=;i<n;i++)
{
if(m>=fo[i].f)
{
ans+=fo[i].j;
m-=fo[i].f;
}
else
{
ans+=m*fo[i].r;
break;
}
}
printf("%.3lf\n",ans);
}
return ;
}
FatMouse' Trade -HZNU寒假集训的更多相关文章
- GlitchBot -HZNU寒假集训
One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a lis ...
- Wooden Sticks -HZNU寒假集训
Wooden Sticks There is a pile of n wooden sticks. The length and weight of each stick are known in a ...
- 今年暑假不AC - HZNU寒假集训
今年暑假不AC "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@#$%^&a ...
- 畅通工程-HZNU寒假集训
畅通工程 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只 ...
- 并查集模板题(The Suspects )HZNU寒假集训
The Suspects Time Limit: 1000MS Memory Limit: 20000KTotal Submissions: 36817 Accepted: 17860 Descrip ...
- 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(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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) ...
- 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- Linux中的查找命令find
原文:http://blog.csdn.net/windone0109/article/details/2817792 查找目录:find /(查找范围) -name '查找关键字' -type d ...
- Chapter 2 User Authentication, Authorization, and Security(1):选择Windows和SQL 身份验证
原文出处:http://blog.csdn.net/dba_huangzj/article/details/38657111,专题目录:http://blog.csdn.net/dba_huangzj ...
- [java]负数的二进制编码——越是基础的越是要掌握
),第二位代表有几个10(即几个101),第三位代表有几个100(即有几个102)-,用小学课本上的说法就是:个位上的数表示几个1,十位上的数表示向个10,百位上的数表示几个100-- 同理可证 ...
- [WinForm]dataGridView动态加载以本地图片显示列
增加一个图片列: C# private void btnQuery_Click(object sender, EventArgs e) { StringBuilder sb=new StringBui ...
- 让Oracle 大小写敏感 表名 字段名 对像名
一.解决方案 1.在表名.字段名.对象名上加上双引号,即可实现让oracle大小写区分. 2.但是这又引起了另一个问题:在数据库操作中,sql语句中相应的表名.字段名.对象名上一定要加双引号. 解决办 ...
- nodejs安装及故障解决
本文来自:http://hxl2009.blog.51cto.com/779549/1031320 给开发搞nodejs环境,遇到点问题记录下过程,备忘. wget http://nodejs.org ...
- ITU-T G.1081 IPTV性能监测点 (Performance monitoring points for IPTV)
ITU-T 建议书 G.1081 IPTV性能监测点 Performance monitoring points for IPTV Summary Successful deployment of I ...
- Android中使用SVG矢量图(一)
SVG矢量图介绍 首先要解释下什么是矢量图像,什么是位图图像? 1.矢量图像:SVG (Scalable Vector Graphics, 可伸缩矢量图形) 是W3C 推出的一种开放标准的文本式矢量图 ...
- Mondrian Schema workbench工作界面 简介(实在懒得写,居然有人弄了,收藏了)
转自:http://hi.baidu.com/dinguangx/item/37e78be29aebc1adcf2d4f89 Schema Schema 定义了一个多维数据库.包含了一个逻辑模型,而这 ...
- ra_interface_lines_all 接口表各字段说明
note:Description and Usage of Fields in RA_INTERFACE_LINES Table [ID 1195997.1] 核心内容: Field Name and ...