zoukankan      html  css  js  c++  java
  • ZOJ-3230-Solving the Problems

    /*ZOJ Problem Set - 3230Solving the Problems
    
    --------------------------------------------------------------------------------
    
    Time Limit: 2 Seconds      Memory Limit: 32768 KB
    
    --------------------------------------------------------------------------------
    
    Programming is fun, Aaron is addicted to it. In order to improve his programming skill, he decides to solve one programming problem per day. As you know, different problems have different properties, some problems are so difficult that there are few people can solve it, while some problems are so easy that almost everyone is able to tackle it.
    
    Programming skill can be measured by an integer p. And all problems are described by two integers ai and bi. ai indicates that if and only if P >= ai, you can solve this problem. bi indicates that after you solve this problem, your programming skill can be increased by bi.
    
    Given the initial programming skill p of Aaron, and the information of each problem, Aaron want to know the maximal programming skill he can reach after m days, can you help him?
    
    Input
    
    Input consists of multiple test cases (less than 40 cases)!
    
    For each test case, the first line contains three numbers: n, m, p (1 <= n <= 100000, 1 <= m <= n, 1 <= p <= 10000), n is the number of problems available for Aaron, m, p as mentioned above.
    
    The following n lines each contain two numbers: ai and bi (1 <= ai <= 10000, 1 <= bi <= 10000) describe the information of the i-th problem as memtioned above.
    
    There's a blank line between consecutive cases.
    
    Output
    
    For each case, output the maximal programming skill Aaron can reach after m days in a line.
    
    Sample Input
    
    2 2 1
    1 2
    7 3
    
    3 1 2
    1 2
    2 3
    3 4
    
    Sample Output
    
    3
    5
    
    
    --------------------------------------------------------------------------------
    Author: ZHOU, Yilun
    Source: ZOJ Monthly, July 2009
    题意:
    我基本可以理解,你也可以的。
    解法:
    开始我对bi从大到小排序,超时,也对每次都从头开始循环,超时才怪。
    看了别人的思路才发现该用ai从小到大排序。每次找优先队列的最大值
    ,即q.top()。
    */
    #include <iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<string.h>
    #include<stdio.h>
    #include<stdlib.h>
    using namespace std;
    #define maxn 260000
    struct PB
    {
        int ai;
        int bi;
        bool operator < (const PB& a)const
        {
            return ai<a.ai;
        }
    } pb[maxn];
    int i,n,m,p;
    int main()
    {
    
        while(~scanf("%d%d%d",&n,&m,&p))
        {
            priority_queue<int> q;//再循环内定义
            for(i=0; i<n; i++)
                scanf("%d%d",&pb[i].ai,&pb[i].bi);
            sort(pb,pb+n);
            i=0;
            while(pb[i].ai<=p&&i<n)
            {
                q.push(pb[i].bi);
                i++;
            }
            while(m--)
            {
                if(!q.empty())
                {
                   p+=q.top();
                   q.pop();
                   while(pb[i].ai<=p&&i<n)
                   {
                       q.push(pb[i].bi);
                       i++;
                   }
                }
                else
                {
                    break;
                }
    
            }
            printf("%d
    ",p);
        }
        return 0;
    }
  • 相关阅读:
    将博客部署到k3s中
    docker/docker swarm学习
    windows共享文件夹使用中的问题(SMB协议)
    洛谷P1280 尼克的任务 题解 动态规划/最短路
    CF1B.Spreadsheets(电子表格) 题解 模拟
    洛谷P1595 信封问题 题解 错排问题
    洛谷P1809 过河问题 经典贪心问题
    CF1238E.Keyboard Purchase 题解 状压/子集划分DP
    洛谷P2719 搞笑世界杯 题解 概率DP入门
    Treap(树堆)入门
  • 原文地址:https://www.cnblogs.com/heqinghui/p/3228258.html
Copyright © 2011-2022 走看看