ACM FatMouse' Trade
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.
InputThe 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.
OutputFor 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
#include<bits/stdc++.h>
using namespace std;
struct node{
int j; /*理想下越大越好*/
int f; /*理想下越小越好*/
double rate; /*性价比*/
}jb[]; bool cmp(node a,node b)
{
if(a.rate != b.rate)
return a.rate > b.rate;
else
return a.f < b.f;
} int main()
{
int m,n;
while(cin>>m>>n) /*m(固定的猫粮) n(房间数)*/
{
if(m==-&&n==-)
break;
for(int i = ; i< n; i++)
{
scanf("%d%d",&jb[i].j,&jb[i].f); /*j(房间内最多的JB数量)f(换购猫粮)*/
jb[i].rate = jb[i].j*1.0/jb[i].f; /*记得在分子*1.0,否则出来的答案只能是int类型的*/
}
sort(jb,jb+n,cmp);
double ans = ; for(int i = ; i < n; i++)
{
//cout<<jb[i].rate<<" "<<jb[i].f<<endl;
if(m >= jb[i].f)
{
ans+=jb[i].j;
m -= jb[i].f;
}else{
ans += jb[i].rate*m; /*根据计算公式推导*/
break;
}
}
printf("%.3lf\n",ans);
}
return ;
}
ACM FatMouse' Trade的更多相关文章
- HDU 1009 FatMouse' Trade(简单贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- 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 ...
- FatMouse' Trade
/* problem: FatMouse' Trade this is greedy problem. firstly:we should calculate the average J[i]/F[i ...
- HDU1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
随机推荐
- Django快速入门
Django 是用 Python 写的一个自由和开放源码 web 应用程序框架.web框架是一套组件,能帮助你更快.更容易地开发web站点.当你开始构建一个web站点时,你总需要一些相似的组件:处理用 ...
- spark2.1:读取hive中存储的多元组(string,double)失败
这两天和同事一起在想着如何把一个表的记录减少,表记录包含了:objectid(主小区信息),gridid(归属栅格),height(高度),rsrp(主小区rsrp),n_objectid(邻区),n ...
- Spark:将RDD[List[String,List[Person]]]中的List[Person]通过spark api保存为hdfs文件时一直出现not serializable task,没办法找到"spark自定义Kryo序列化输入输出API"
声明:本文转自<在Spark中自定义Kryo序列化输入输出API> 在Spark中内置支持两种系列化格式:(1).Java serialization:(2).Kryo seriali ...
- shell多进程脚本
#!/bin/bash python_path=/home/huaw/crawler python_name=list_all_v6_crawler.py MAX_SYNC_PROCESS=40 ec ...
- supervisor安装使用和我踩过的坑
什么是supervisor: supervisor是一款用python编写的进程管理工具,主要运行于linux系统,不支持windows系统,目前还不能运行于python3下. step1:安装sup ...
- Android系统框架构
写此本文是为了对Android系统框架有一个整体的认识和了解,对于开发和测试人员脑子里要有整体认识以便对工作有所帮助. 进入正题 首先Android系统架构采用了分层架构的思想,共分为四层由上到下分: ...
- jQuery系列 第三章 jQuery框架操作CSS
第三章 jQuery框架操作CSS 3.1 jQuery框架的CSS方法 jQuery框架提供了css方法,我们通过调用该方法传递对应的参数,可以方便的来批量设置标签的CSS样式. 使用JavaScr ...
- Python进阶_mysql(1)
什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据. 进入mysql (linux ...
- 远程连接服务器jupyter notebook、浏览器以及深度学习可视化方法
h1 { counter-reset: h2counter; } h2 { counter-reset: h3counter; } h3 { counter-reset: h4counter; } h ...
- 创建类似于Oracle中SYS_GUID() 的方法
CREATE or REPLACE FUNCTION "sys_guid"()RETURNS "pg_catalog"."varchar" ...