hdu 1009 FatMouse' Trade

原创 2018年04月16日 20:13:19

FatMouse' Trade

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90222    Accepted Submission(s): 31257


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
 

Author
CHEN, Yue
 
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
#define N 1005
typedef long long LL;

struct node{
    double j;
    double f;
}t[N];

bool cmp(node x, node y){
    if((x.j / x.f) > (y.j / y.f)){
        return true;
    }
    else
        return false;
}


int main(){
    int m, n;
    double a, b;
    while(scanf("%d%d", &m, &n) != EOF && m != -1 && n != -1){
        for(int i = 0; i < n; i++){
            scanf("%lf%lf", &a, &b);
            t[i].j = a;
            t[i].f = b;
        }
        sort(t, t+n, cmp);
        double ans = 0;
        for(int i = 0; i < n; i++){
            if(m){
                if(m < t[i].f){
                    ans += (t[i].j/t[i].f)*m;
                    m = 0;
                }
                else{
                    ans += t[i].j;
                    m -= t[i].f;
                }
            }
            else{
                break;
            }
        }
        printf("%.3lf\n", ans);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guihaiyuan123/article/details/79965730

HDU-1009-FatMouse' Trade(简单贪心!)

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
  • qq_16542775
  • qq_16542775
  • 2015-11-16 17:47:40
  • 676

杭电ACM 1009:FatMouse' Trade

原创作品 转载请注明出http://blog.csdn.net/always2015/article/details/47747077这一道题意思就是老鼠用猫食物换取自己最喜爱的食物javaBean的...
  • Always2015
  • Always2015
  • 2015-08-18 09:44:10
  • 1597

hdu-1009 FatMouse' Trade 贪心算法

Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding...
  • qq_38280242
  • qq_38280242
  • 2017-08-17 14:46:58
  • 98

FatMouse' Trade hdu1009 贪心算法

http://acm.hdu.edu.cn/showproblem.php?pid=1009 开始贪心专题。 题意:一共有n个房子,每个房子里有老鼠喜欢吃的javabeans,但是每个房间里的ja...
  • operator456
  • operator456
  • 2013-01-24 19:25:16
  • 4437

ACM--猫鼠交易--贪心--HDOJ 1009--FatMouse' Trade

HDOJ题目地址:传送门 FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3...
  • qq_26891045
  • qq_26891045
  • 2016-05-27 13:54:23
  • 1063

HDU FatMouse' Trade

FatMouse' Trade Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) To...
  • zp___waj
  • zp___waj
  • 2015-05-26 12:45:56
  • 590

HDU1009:FatMouse' Trade

Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding t...
  • libin56842
  • libin56842
  • 2013-04-16 22:08:53
  • 6592

FatMouse' Trade(贪心算法)

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
  • baidu_23955875
  • baidu_23955875
  • 2014-12-15 17:24:44
  • 1541

杭电OJ ——1009——FatMouse' Trade

FatMouse' Trade                                               Time Limit: 2000/1000 MS (Java/Others)...
  • lishuhuakai
  • lishuhuakai
  • 2012-09-20 01:16:34
  • 2418

FatMouse' Trade hdu 1009

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)...
  • u011471397
  • u011471397
  • 2013-08-30 14:09:19
  • 745
收藏助手
不良信息举报
您举报文章:hdu 1009 FatMouse' Trade
举报原因:
原因补充:

(最多只允许输入30个字)