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. ansible配置mysql主从复制

    配置主机1.下载安装所需安装包 [root@server1 ansible]# lsansible-2.7.8-1.el7.noarch.rpmansible-tower-setup-bundle-3 ...

  2. chmod - 改变文件的访问权限

    总揽 chmod [options] mode file... POSIX 选项: [-R] GNU 选项 (最短方式): [-cfvR] [--reference=rfile] [--help] [ ...

  3. CAD交互绘制虚线(com接口)

    用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...

  4. 除了上万的月薪之外,还有什么理由让我们必须学Python?

    虽然目前的编程语言有很多,但是基础语法上的概念,本质上都是相通的.可以做到一通百通.所以没有必要为了学哪门语言纠结太多. python是目前市面上,我个人认为是最简洁&&最优雅& ...

  5. Spring boot 配置tomcat后 控制台不打印SQL日志

    在pom.xml中配置tomcat启动处加上: <dependency> <groupId>org.springframework.boot</groupId> & ...

  6. tinyxml

    在TinyXML中,根据XML的各种元素来定义了一些类:        TiXmlBase:整个TinyXML模型的基类.        TiXmlAttribute:对应于XML中的元素的属性.   ...

  7. [Python3网络爬虫开发实战] 1.2.2-Selenium的安装

    Selenium是一个自动化测试工具,利用它我们可以驱动浏览器执行特定的动作,如点击.下拉等操作.对于一些JavaScript渲染的页面来说,这种抓取方式非常有效.下面我们来看看Selenium的安装 ...

  8. pxc集群安装

    一.pxc镜像url:https://hub.docker.com/r/percona/percona-xtradb-cluster/ 二.安装及重命名: 1.安装:docker pull perco ...

  9. xtrbackup备份mysql

    mysqldump备份方式是采用逻辑备份,但是它最大的缺陷就是备份和恢复速度慢对于一个小于50G的数据库而言,这个速度还是能接受的,但如果数据库非常大,那再使用mysqldump备份就不太适合了. x ...

  10. 15Spring AOP基础

    为什么需要AOP? 先来看一段代码: package com.cn.spring.aop.helloworld; //加减乘除的接口类 public interface ArithmeticCalcu ...