Greedy Mouse

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

A fat mouse prepared M pounds of cat food,ready to trade with the cats guarding the warehouse containing his

favorite food:peanut. The warehouse has N rooms.The ith room containsW[i] pounds of peanut and requires

F[i] pounds of cat food. Fatmouse does not have to trade for all the peanut in the room,instead,he may get

W[i]*a% pounds of peanut if he pays F[i]*a% pounds of cat food.The mouse is a stupid mouse,so can you tell

him the maximum amount of peanut he can obtain.

 
输入
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 W[i] and F[i] respectively. The test case is terminated by two -1. All integers are not greater than 1000.
输出
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of penaut that FatMouse can obtain.
样例输入
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
样例输出
13.333
31.500基本的背包问题,用贪心求解
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <utility>
using namespace std;
typedef pair<double,double> W;
bool cmp(const W& a,const W& b){ return a.first > b.first;}
int main(){
    double m;
    int n;
     && n!=-){
        vector<W> exchange(n);
         ; i < n; ++ i){
            double w,f;
            cin >>w >>f;
            exchange[i].first = w/f;
            exchange[i].second = w;
        }
        sort(exchange.begin(),exchange.end(), cmp);
        ;
         ; i < n && m; ++i){
            if(m > exchange[i].second/exchange[i].first){
                res += exchange[i].second;
                m -= exchange[i].second/exchange[i].first;
            }else{
                res+=m*exchange[i].first;
                break;
            }
        }
        printf("%0.3f\n",res);
    }
}

 

ACM Greedy Mouse的更多相关文章

  1. POJ1386Play on Words[有向图欧拉路]

    Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11846   Accepted: 4050 De ...

  2. SPOJ Play on Words

    传送门 WORDS1 - Play on Words #graph-theory #euler-circuit Some of the secret doors contain a very inte ...

  3. Play on Words[HDU1116]

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. POJ 1386 Play on Words(欧拉图的判断)

    Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11838   Accepted: 4048 De ...

  5. 欧拉通路-Play on Words 分类: POJ 图论 2015-08-06 19:13 4人阅读 评论(0) 收藏

    Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10620 Accepted: 3602 Descri ...

  6. hdu 1116 Play on Words 欧拉路径+并查集

    Play on Words Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. Play on Words(有向图欧拉路)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8571   Accepted: 2997 Description Some ...

  8. hdu 1116 Play on Words(欧拉通路)

    Problem Description Some of the secret doors contain a very interesting word puzzle. The team of arc ...

  9. uva 10129 poj 1386 hdu 1116 zoj 2016 play on words

    //本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!! 题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点 ...

随机推荐

  1. thinkphp 数据访问

    <?php namespace Admin\Controller; use Think\Controller; class MainController extends Controller { ...

  2. CentOS7 bonding配置

    操作系统:CentOS Linux release 7.1.1503 (Core) 网卡适配器: eno1.eno2 bonding类型:mode=1 (active-backup),主-备份策略 网 ...

  3. Delphi实现窗体内嵌其他应用程序窗体

    实现原理是启动一个应用程序,通过ProcessID得到窗体句柄,然后对其设定父窗体句柄为本程序某控件句柄(本例是窗体内一个Panel的句柄),这样就达成了内嵌的效果. 本文实现的是内嵌一个记事本程序, ...

  4. java学习第5天

    一维数组完了就是二维数组,和一位数组类似 .我们定义二维数组用的是 int[] []arr=new int[m][n],与一维类似,它在堆内存中存放,并以地址的形式访问,如下图..   而遍历二维数组 ...

  5. SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)

    一. 1.定义接口 Suppose that you need to authenticate against users in a non-relational database suchas Mo ...

  6. yii2源码学习笔记(七)

    今天继续了解model类 /** 2 * Returns the form name that this model class should use. 3 * 4 * 返回表单的名称,就是这个 mo ...

  7. qt二维码示例

    原创文章,引用请保证原文完整性,尊重作者劳动,原文地址http://blog.csdn.net/hiwubihe/article/details/38679621,qq:1269122125. 移动终 ...

  8. Spring 入门 AOP

    通过一个小例子演视怎么使用 Spring 现实面向切面编程. 导入 Spring 所需要的包 spring-framework-2.5.6 版需要导入以下包: 1.----- spring.jar 2 ...

  9. TCP慢启动算法

    慢启动定义 慢启动,是传输控制协议使用的一种阻塞控制机制.慢启动也叫做指数增长期.慢启动是指每次TCP接收窗口收到确认时都会增长.增加的大小就是已确认段的数目.这种情况一直保持到要么没有收到一些段,要 ...

  10. Java 网络编程(三) 创建和使用URL访问网络上的资源

    链接地址:http://www.cnblogs.com/mengdd/archive/2013/03/09/2951877.html 创建和使用URL访问网络上的资源 URL(Uniform Reso ...