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=; i<n; i++)
scanf("%d%d",&pb[i].ai,&pb[i].bi);
sort(pb,pb+n);
i=;
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\n",p);
}
return ;
}
ZOJ-3230-Solving the Problems的更多相关文章
- ZOJ 3230 Solving the Problems(数学 优先队列啊)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230 Programming is fun, Aaron is ...
- TED #09# You don't have to be an expert to solve big problems
Tapiwa Chiwewe: You don't have to be an expert to solve big problems Collection noticed a haze hangi ...
- Elixir - Hey, two great tastes that go great together!
这是Elixir的作者 José Valim 参与的一次技术访谈,很有料,我们可以了解Elixir的一些设计初衷,目标等等. 原文在: http://rubyrogues.com/114-rr-eli ...
- (转)A Survival Guide to a PhD
Andrej Karpathy blog About Hacker's guide to Neural Networks A Survival Guide to a PhD Sep 7, 2016 T ...
- hdu 5057 Argestes and Sequence(分块算法)
Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))
传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...
- How to (seriously) read a scientific paper
How to (seriously) read a scientific paper Adam Ruben’s tongue-in-cheek column about the common diff ...
- July 3rd, Week 28th Sunday, 2016
2016-07-03 First-hand experience is often necessary for personal growth. 亲身体验通常是成长所必须的. Although som ...
- hdu5057 Argestes and Sequence 分块
Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submiss ...
- Codeforces 528D Fuzzy Search(FFT)
题目 Source http://codeforces.com/problemset/problem/528/D Description Leonid works for a small and pr ...
随机推荐
- hdu 2204 Eddy's爱好 容斥原理
Eddy's爱好 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- 上海仪电Azure Stack技术深入浅出系列2:Azure Stack与Azure的有QoS保证的网络联通实现方法和对比测试
本篇文章作为<Azure Stack技术深入浅出系列>的第二篇,将描述我们目前在构建基于Azure Stack混合云业务解决方案方面所面临的网络连通困难,以及相关技术人员为解决这一问题所做 ...
- torch中的多线程threads学习
torch中的多线程threads学习 torch threads threads 包介绍 threads package的优势点: 程序中线程可以随时创建 Jobs被以回调函数的形式提交给线程系统, ...
- 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2806 Accepted: ...
- mysql远程连接的设置
有时数据库所在机器与项目运行的机器不是同一个,那么就涉及到远程链接数据库了,配置远程连接数据库的步骤如下: 1.查看mysql数据库中,user表中的信息,如下图,先使用use mysql切换到mys ...
- OMAP4之DSP核(Tesla)软件开发学习(一)
目的: 目前手上正在OMAP4上做东西,由于涉及到大量运算,交给arm A9双核发现运算速度很慢,不能满足需求.故考虑将大量运算任务(比如FIR.FFT.卷积.图像处理.向量运算等)交给O ...
- 网站微信登录-python 实现
最近微信登录开放公测,为了方便微信用户使用,我们的产品也决定加上微信登录功能,然后就有了这篇笔记. 根据需求选择相应的登录方式 微信现在提供两种登录接入方式 移动应用微信登录 网站应用微信登录 这里我 ...
- cool 软件 —— Carnac(实时桌面显示按键)
1. Carnac 下载地址:Carnac, the Magnificent Keyboard Utility 使用说明:carnac – 在屏幕实时显示按键操作
- Spring map注入
类test.Configurations定义如下 @Getter @Setter public class Configurations { private Map<AnswerSourceTy ...
- UITableView-(单元格的自定义方法)
//contentView //行内容 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS ...