FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 53352    Accepted Submission(s): 17788

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.
 
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 有m个猫食n个房间,每一个房间都有一个猫把守。每一个房间都有j个你想要的东西,要得到东西。就要给猫猫食
每一个猫都有规定的猫食,你给的猫食所占规定的比例就是你得到东西的比例,球最多能得多少个
简单贪心。排序,求值
2015,7,20
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node{
int j,f;
double v;
}a[1100];
bool cmp(node x,node y){
return x.v<y.v;
}
int main(){
int m,n,i;
while(~scanf("%d%d",&m,&n),!(m==-1&&n==-1)){
for(i=0;i<n;i++){
scanf("%d%d",&a[i].j,&a[i].f);
a[i].v=a[i].f*1.0/a[i].j;
}
sort(a,a+n,cmp);
double sum=0;
for(i=0;i<n;i++){
if(m>=a[i].f){
sum+=a[i].j;
m-=a[i].f;
}
else{
double c;
c=m*1.0/a[i].f;
sum+=a[i].j*c;
break;
}
}
printf("%.3lf\n",sum);
}
return 0;
}

hdu 1009 FatMouse&#39; Trade的更多相关文章

  1. HDU 1009 FatMouse' Trade(简单贪心)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  2. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  3. HDU 1009:FatMouse&#39; Trade(简单贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  5. Hdu 1009 FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. hdu 1009:FatMouse' Trade(贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. 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) ...

  8. FatMouse&#39; Trade(杭电1009)

    FatMouse' Trade Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tot ...

  9. HDU 1009 FatMouse' Trade(贪心)

    FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...

随机推荐

  1. laravel学习:php写一个简单的ioc服务管理容器

    php写一个简单的ioc服务管理容器 原创: 陈晨 CoderStory 2018-01-14 最近学习laravel框架,了解到laravel核心是一个大容器,这个容器负责几乎所有服务组件的实例化以 ...

  2. jquery 移动端 六位密码输入

    <!DOCTYPE html> <html> <head> <script src="scripts/jquery-1.7.1.min.js&quo ...

  3. element-UI el-table二次封装

    Part.1 为什么要二次封装? 这是 Element 网站的 table 示例: <template> <el-table :data="tableData" ...

  4. 了解Java密码扩展的基础

      了解Java密码扩展的基础     Java密码扩展(The Java Cryptography Extension),是JDK1.4的一个重要部分,基本上,他是由一些包构成的,这些包形成了一个框 ...

  5. Spring MVC全局异常后返回JSON异常数据

    问题: 当前项目是作为手机APP后台支持,使用spring mvc + mybaits + shiro进行开发.后台服务与手机端交互是发送JSON数据.如果后台发生异常,会直接返回异常页面,显示异常内 ...

  6. 03CSS内容背景

    CSS内容背景 设置背景颜色——background-color  插入背景图片——background-image  设置背景图片位置——background-position 设置重复背景图片—— ...

  7. java.lang.IllegalArgumentException: Result Maps collection already contains value for com.zhmy.businessapi.mapper.CompanyMapper.BaseResultMap

    复制mybatis的mapper.xml文件修改后,忘记将xml中的mapper标签里的namespace更换成对应类了,修改完即可

  8. 在前后端分离的SpringBoot项目中集成Shiro权限框架

    参考[1].在前后端分离的SpringBoot项目中集成Shiro权限框架 参考[2]. Springboot + Vue + shiro 实现前后端分离.权限控制   以及跨域的问题也有涉及

  9. elementui 后台管理系统遇到的问题(二) 树形控件 el-tree

    elementui中树形控件的使用 一.将后台返回的数据填充到前端控件中,需要注意的几点问题 (1).el-tree中需要绑定node-key='自定义的id名称' (2).在配置data中defau ...

  10. layuiAdmin 项目修改

    layuiAdmin修改 index.js 修改登录url user/login=>publics/login config.js 修改 name 项目名称, tokenName token字段 ...