zoukankan      html  css  js  c++  java
  • HDU 3039 Go Home

    今天本来解决的很好,本来可以不聊那么结束,但是我想更完美一点,多聊几句,谁知道就聊了很长时间,很傻逼。耽误了时间!

    /*************************************************************************************************/

    Go Home

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 400    Accepted Submission(s): 169
    Problem Description
    There comes the holiday, Partychen set foot on the way home. He takes some ECNU coins to hire bodyguards to prevent from being robbed before he went home. But the bodyguard takes one coin for every kilometer. If Partychen walks without bodyguard , he will be robbed one ECNU coin by every robber on every kilometer . Of course , he can choose where to hire bodyguard or where to be robbed as he like.
    For example , there are two roads on his way home and he wants to use 8 ECNU coins to hire bodyguard , the first road takes 4 kilometers with 5 robbers ( per kilometer ) and the second takes 5 kilometers with 6 robbers. He could choose the last 3 kilometers on the first road and the whole kilometers on the second road to hire bodyguard to protect him, and leave the first kilometer on the first road to be robbed by 5 robbers, which he will be robbed 5 ECNU coins.
    Now , Partychen want to know how many ECNU coins will be robbed at least.
     
    Input
    It consists of multi-case .
    Every case starts with two integers N and M ( 0≦N≦10,000, 0≦M≦1,000,000,000 ) which means that there are N roads and M ECNU coins to hire bodyguard.
    The followed N lines contains two integers D and P (1<=D<=10,000 , 0<=P<=10 ) , which means the length of every road and the number of robbers in every kilometer on this road.
    End with N=0 and M=0 .
     
    Output
    An integer means the number of ECNU coins to be robbed at least.
     
    Sample Input
    2 8 4 5 5 6 3 1 5 10 5 10 5 10 0 0
     
    Sample Output
    5 140
     
    Source
     
    Recommend
    lcy
     
    贪心,暗每千米的强盗数降序排即可
    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<string.h>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define N 12345
    struct node
    {
        int a,b;
    }c[N];
    int cmp(node n1,node n2)
    {
        return n1.b > n2.b;
    }
    int main()
    {
        int n,m;
        while(~scanf("%d%d",&n,&m)&&(n+m))
        {
            int sum=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d%d",&c[i].a,&c[i].b);
                sum+=c[i].a*c[i].b;
            }
            sort(c,c+n,cmp);
            for(int i=0;i<n;i++)
            {
                if(m>=c[i].a)
                {
                    sum-=c[i].b*c[i].a;
                    m-=c[i].a;
                }
                else
                {
                    sum-=c[i].b*m;
                    break;
                }
            }
            cout<<sum<<endl;
        }
        return 0;
    }
  • 相关阅读:
    SQL练习题32:请你创建一个actor_name表,并且将actor表中的所有first_name以及last_name导入该表.
    SQL练习题31:对于表actor批量插入如下数据,如果数据已经存在,请忽略(不支持使用replace操作)
    SQL练习题30:对于表actor批量插入如下数据(不能有2条insert语句哦!)
    npm run dev 报错:missing script:dev
    [转]vue中“:”、“.”、“@”的意义
    Vue踩坑记录
    Vue指令:v-clock解决页面闪烁问题
    npm-安装模块时出现rollbackFailedOptional
    js中[]、{}、()的区别
    IDEA离线安装插件
  • 原文地址:https://www.cnblogs.com/wmxl/p/4697131.html
Copyright © 2011-2022 走看看