hdu 2111 Saving HDU

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

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

struct node
{
    int j,v;
    double bi;
} data[105];

bool cmp(const node &a,const node &b)
{
    if(a.j>b.j)
    return true;
    else return false;
}

int main()
{
    int v,n;
    double ans;
    while(cin>>v&&v)
    {
        cin>>n;
        ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>data[i].j>>data[i].v;
            data[i].bi=(double)data[i].j/(double)data[i].v*1.0;
        }
        sort(data,data+n,cmp);
        for(int i=0;i<n;i++)
        {
            if(v>=data[i].v)
            {
                v=v-data[i].v;
                ans+=data[i].j*data[i].v;
            }
            else
            {
                ans+=v*data[i].j;
                break;
            }
        }
        printf("%.0lf\n",ans);
    }
    return 0;
}
时间: 2024-11-03 05:43:23

hdu 2111 Saving HDU的相关文章

HDU 2111 Saving HDU (贪心)

Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5233    Accepted Submission(s): 2387 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的. 一天,当他正在苦思冥想解困良策的时

【贪心专题】HDU 1257 最少拦截系统&amp;&amp;HDU 2111 Saving HDU (选宝贝)

链接:click here~~ 题意: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统. [解题思路]: 直接模拟一边就可以,不知道想简单了还是数据

HDU 2111 Saving HDU【贪心】

解题思路:排序后贪心,和fatmouse's  trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5837    Accepted Submission(s): 2692 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏

HDOJ 2111. Saving HDU 贪心 结构体排序

Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7194    Accepted Submission(s): 3345 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.  一天,当他正在苦思冥想解困良策的

HDU 4308 Saving Princess claire_

BFS问题. 题意是问 王子救公主 需要花费多少钱.每路过一个 * 就要支付 cost 那么多的钱.求最短. 多个P 传送点就 多个点进队即可. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<map> #include<stack> #include<iostream&g

HDU 1245 Saving James Bond

计算几何+SPFA 我已经不想看我的提交记录了.... HDU 我起码WA了2页.... 都是浮点数惹的祸. const double eps=1e-4; abs(a-b)<=eps; 这样来判断相等. 总共 n 条鳄鱼,最多有 n*(n+1)/2 条路. 抽象化处理. 把 中心的起点当作 起点0 : 最多有 n+1 条路. 把鳄鱼和周围的边界的终点都当作 n+1 ; 最多有 n+1 条 总共就只存在 n+2个点. 就是计算0 和 n+1 的最短距离. 有个小优化,就是当 跳跃距离能够直接跳到岸

HDU 3037 Saving Beans (Lucas定理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3037 推出公式为C(n + m, m) % p, 用Lucas定理求大组合数取模的值 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int t; long long n, m, p; long long pow(long long n, long lo

Saving HDU

mnesia在频繁操作数据的过程可能会报错:** WARNING ** Mnesia is overloaded: {dump_log, write_threshold},可以看出,mnesia应该是过载了.这个警告在mnesia dump操作会发生这个问题,表类型为disc_only_copies .disc_copies都可能会发生. 如何重现这个问题,例子的场景是多个进程同时在不断地mnesia:dirty_write/2 mnesia过载分析 1.抛出警告是在mnesia 增加dump

hdu 3037 Saving Beans(组合数学)

hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数. 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m.可是n,m非常大,所以用到Lucas定理. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll n, m, p; ll qPow (ll a