思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys
- /*
- 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达
- 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排个序,从大到小询问,那么之前添加的穿越点都是有效的,
- 用multiset保存。比赛时想到了排序,但是无法用线段树实现查询,stl大法好!
- */
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <set>
- #include <iostream>
- using namespace std;
- const int MAXN = 1e5 + ;
- const int INF = 0x3f3f3f3f;
- struct Year {
- int u, v;
- bool operator < (const Year &r) const {
- return u > r.u;
- }
- }y[MAXN];
- struct Query {
- int p, id;
- bool operator < (const Query &r) const {
- return p > r.p;
- }
- }q[MAXN];
- int ans[MAXN];
- int a[];
- int n, m, l;
- int main(void) { //ZOJ Monthly, July 2015 - H Twelves Monkeys
- //freopen ("H.in", "r", stdin);
- while (scanf ("%d%d%d", &n, &m, &l) == ) {
- for (int i=; i<=m; ++i) {
- scanf ("%d%d", &y[i].u, &y[i].v);
- }
- for (int i=; i<=l; ++i) {
- scanf ("%d", &q[i].p); q[i].id = i;
- }
- sort (y+, y++m); sort (q+, q++l);
- multiset<int> S; int j = ;
- for (int i=; i<=l; ++i) {
- while (j <= m && y[j].u >= q[i].p) {
- S.insert (y[j].v); j++;
- }
- multiset<int>::iterator it; int cnt = ;
- for (it=S.begin (); it!=S.end (); ++it) {
- a[++cnt] = *(it); if (cnt == ) break;
- }
- if (cnt == && a[] <= q[i].p) ans[q[i].id] = q[i].p - a[];
- else ans[q[i].id] = ;
- }
- for (int i=; i<=l; ++i)
- printf ("%d\n", ans[i]);
- }
- return ;
- }
思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys的更多相关文章
- Twelves Monkeys (multiset解法 141 - ZOJ Monthly, July 2015 - H)
Twelves Monkeys Time Limit: 5 Seconds Memory Limit: 32768 KB James Cole is a convicted criminal ...
- ZOJ 3913 Bob wants to pour water ZOJ Monthly, October 2015 - H
Bob wants to pour water Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge There i ...
- ZOJ 3910 Market ZOJ Monthly, October 2015 - H
Market Time Limit: 2 Seconds Memory Limit: 65536 KB There's a fruit market in Byteland. The sal ...
- ZOJ Monthly, July 2015
B http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5552 输入n,表示有n个数1到n.A先拿,B后拿,依次拿,每次可以拿任意一 ...
- ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F
Number Game Time Limit: 2 Seconds Memory Limit: 65536 KB The bored Bob is playing a number game ...
- 143 - ZOJ Monthly, October 2015 I Prime Query 线段树
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- ZOJ 3905 Cake ZOJ Monthly, October 2015 - C
Cake Time Limit: 4 Seconds Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...
- ZOJ 3903 Ant ZOJ Monthly, October 2015 - A
Ant Time Limit: 1 Second Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...
随机推荐
- T1003 电话连线 codevs
http://codevs.cn/problem/1003/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一个国家有n个城市 ...
- cogs——1001. [WZOI2011 S3] 消息传递
1001. [WZOI2011 S3] 消息传递 ★★ 输入文件:messagew.in 输出文件:messagew.out 简单对比时间限制:1 s 内存限制:128 MB Prob ...
- 创建简单的spring-mvc项目
1.第一步:创建项目 new—>Dynamic Web Project 项目创建成功后,展示如图: 2.第二步:导入springmvc的jar包和common-logging.jar 3.第三步 ...
- 解析excel文件并将数据导入到数据库中
今天领导给安排了一个临时工作,让我将一个excel里面的数据解析后放入数据库中,经过一个下午的努力成功完成,现在将代码献上,希望对大家有所帮助 一.需要导入的jar 1.commons-collect ...
- 苹果Macbook Air怎么安装Win7系统图解教程
下面开始我们在苹果Macbook Air上的Windows7之旅吧.
- ArcGIS Python 编码问题
吐槽一下ArcGIS自带的 Python IDE, 没有代码补全 没有函数提示 没有代码折叠 没有行号 撤销操作还有问题 字符编码还有各种问题 ......... 花了2天时间才琢磨出来的经验 环 ...
- C# .NET Visual Studio VS2008如何显示行号
工具-选项,然后勾选"显示所有设置",然后在文本编辑器下面找到所有语言,勾选"行号"即可.
- Oracle中长度为0字符串与null等价
不试不知道,Oracle中,长度为0的字符串'' 居然与null等价! 众所周知,null代表空,什么都不存在,而一个字符串'',虽然长度为0,但毕竟已经是一个字符串,二者怎么能等价,混为一谈呢. 在 ...
- poj1151==codevs 3044 矩形面积求并
Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21511 Accepted: 8110 Descrip ...
- 【bzoj1303】[CQOI2009]中位数图
一个大于b的数和一个小于b的数可以互相抵消,所以我们用1和-1表示. 从b向两边扩展,left[i]表示b左边抵消后有i个数比b小的可能数,right[i]表示b右边抵消后有i个数比b大的可能数. a ...