ZOJ 3230 Solving the Problems(数学 优先队列啊)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230
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
题意:
给出Aaron 的初始的做题能力值,然后给出N道题:Aaron 解决这道题至少须要多少能力值a。Aaron 攻克了这道题他能添加多少能力值b!
求M天后Aaron 的最大能力值是多少!
PS:
运用优先队列。分别对a和b排序一下!
代码例如以下:
//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
//const double pi = atan(1.0)*4;
const double pi = 3.1415926535897932384626;
const double e = exp(1.0);
#define INF 0x3f3f3f3f
//#define INF 1e18
//typedef long long LL;
//typedef __int64 LL;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
struct node1
{
int a, b;
node1() {}
node1(int _a, int _b): a(_a), b(_b) {}
bool operator < (const node1 & x) const
{
return a > x.a;//最小值优先
}
};
struct node2
{
int a, b;
node2() {}
node2(int _a, int _b): a(_a), b(_b) {}
bool operator < (const node2 & x) const
{
return b < x.b;//最大值优先
}
};
int n, m, p; int main()
{
int a, b;
while(~scanf("%d%d%d", &n, &m, &p))
{
priority_queue<node1> q1;
priority_queue<node2> q2; for(int i = 0; i < n; i++)
{
scanf("%d%d", &a, &b);
q1.push(node1(a, b));
}
int maxx_p = p;
for(int i = 0; i < m; i++)
{
while (!q1.empty())
{
int tt_a = q1.top().a;
int tt_b = q1.top().b;
if(tt_a <= maxx_p)
{
q2.push(node2(tt_a, tt_b));
q1.pop();
}
else
{
break;
}
}
if (q2.empty())
{
break;
}
maxx_p += q2.top().b;
q2.pop();
}
printf("%d\n", maxx_p);
}
return 0;
}
/*
3 1 2
1 2
2 3
3 4
3 2 2
1 2
2 3
3 4
*/
ZOJ 3230 Solving the Problems(数学 优先队列啊)的更多相关文章
- zoj 3946 Highway Project(最短路 + 优先队列)
Highway Project Time Limit: 2 Seconds Memory Limit: 65536 KB Edward, the emperor of the Marjar ...
- ZOJ 2724 Windows 消息队列 (优先队列)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 Message queue is the basic fund ...
- zoj 2722 Head-to-Head Match(数学思维)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2722 题目描述: Our school is planning ...
- zoj 1028 Flip and Shift(数学)
Flip and Shift Time Limit: 2 Seconds Memory Limit: 65536 KB This puzzle consists of a random se ...
- ZOJ 2679 Old Bill(数学)
主题链接:problemCode=2679" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProbl ...
- ZOJ 2680 Clock()数学
主题链接:problemId=1680" target="_blank">http://acm.zju.edu.cn/onlinejudge/showProblem ...
- ZOJ - 3946-Highway Project(最短路变形+优先队列优化)
Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can ...
- ZOJ 3203 Light Bulb(数学对勾函数)
Light Bulb Time Limit: 1 Second Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...
- ZOJ - 3866 Cylinder Candy 【数学】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3866 思路 积分 参考博客 https://blog.csdn. ...
随机推荐
- LDAP学习小结【仅原理和基础篇】
此篇文章花费了好几个晚上,大部分是软件翻译的英文文档,加上自己的理解所写,希望学习者能尊重每个人的努力. 我有句话想送给每个看我文章的人: 慢就是快,快就是慢!!! 另外更希望更多人能从认真从原理学习 ...
- python算法-栈
定义: 栈(stack)又名堆栈,它是一种运算受限的线性表.其限制是仅允许在表的一端进行插入和删除运算.这一端被称为栈顶,相对地,把另一端称为栈底.向一个栈插入新元素又称作进栈.入栈或压栈,它是把新元 ...
- linux 第五部分 系统管理员 网络设定与备份
linux 第五部分 系统管理员 网络设定与备份 系统基本设置 1.网络的设置 手动设置与dhcp自动获得 以及更改主机名称 centos 7 对网卡编号的规则 enol1 b ...
- [android 应用开发]android 分层
1 应用层, 2 应用框架层(框架是所有开发人员共同使用和遵守的约定) 3 系统运行库层 4 linux内核层
- 82. Spring Boot – 启动彩蛋【从零开始学Spring Boot】
我们在[28. SpringBoot启动时的Banner设置 ] 这一小节介绍过设置Spring Boot的Banner,但是实际当中,我们希望做的更漂亮,所以也就有了这小节Spring Boot-启 ...
- .NET重构(九):机房重构验收总结
导读:机房收费系统个人重构版,在寒假前,已经结束了.嗯,这一路的过程,也挺心酸的.结合师傅验收时的指导.建议,对这一段时间的学习,进行一个总结. 一.学习过程 这一阶段的学习,按照师傅给的建议是:由浅 ...
- HDU-4612 Warm up,tarjan求桥缩点再求树的直径!注意重边
Warm up 虽然网上题解这么多,感觉写下来并不是跟别人竞争访问量的,而是证明自己从前努力过,以后回头复习参考! 题意:n个点由m条无向边连接,求加一条边后桥的最少数量. 思路:如标题,tarjan ...
- MySQL5.7 服务 crash 后无法启动
事发背景 测试环境更换数据盘,直接采取在线将数据目录暴力拷贝到新盘,然后将原服务关闭,启用新盘. 服务是可以正常启动的,但是没多会开发就反应服务down了,错误日志输出 -- :: InnoDB: F ...
- 总结搭建Oracle11g DG踩的坑
此次的操作环境是Oracle11g 单实例,os为Linux,采用duplicate在线创建物理备库 primary上设置相关参数 ALTER SYSTEM SET LOG_ARCHIVE_CONFI ...
- [BZOJ2523][Ctsc2001]聪明的学生
[BZOJ2523][Ctsc2001]聪明的学生 试题描述 一位教授逻辑学的教授有三名非常善于推理且精于心算的学生A,B和C.有一天,教授给他们三人出了一道题:教授在每个人脑门上贴了一张纸条并告诉他 ...