http://codeforces.com/contest/612/problem/D
4 seconds
256 megabytes
standard input
standard output
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 106) — the number of segments and the value of k.
The next n lines contain two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109) each — the endpoints of the i-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.
First line contains integer m — the smallest number of segments.
Next m lines contain two integers aj, bj (aj ≤ bj) — the ends of j-th segment in the answer. The segments should be listed in the order from left to right.
3 2
0 5
-3 2
3 8
2
0 2
3 5
3 2
0 5
-3 3
3 8
1
0 5
题意:给N个区间求被覆盖K次的区间。
题解:用线段扫描左端点(用-1标记)进入tmp++,右端点(用1标记)出来tmp--,当tmp为k时就是答案区间。
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
using namespace std;
vector<int>ans;
vector<pii>s;
int n,k;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
cin>>n>>k;
for(int i=;i<n;i++)
{
int a,b;
cin>>a>>b;
s.pb(mp(a,-));
s.pb(mp(b,));
}
sort(s.begin(),s.end());
int tmp=;
for(int i=;i<s.size();i++)
{
if(s[i].second==-)
{
tmp++;
if(tmp==k)ans.pb(s[i].first);
}
else
{
if(tmp==k)ans.pb(s[i].first);
tmp--;
}
}
cout<<ans.size()/<<endl;
for(int i=;i<ans.size()/;i++)
{
cout<<ans[*i]<<" "<<ans[*i+]<<endl;
}
}
http://codeforces.com/contest/612/problem/D的更多相关文章
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
- http://codeforces.com/contest/555/problem/B
比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...
- http://codeforces.com/contest/610/problem/D
D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/536/problem/B
B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- http://codeforces.com/contest/535/problem/C
C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- http://codeforces.com/contest/838/problem/A
A. Binary Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- http://codeforces.com/contest/402/problem/E
E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces.com/contest/251/problem/C
C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- 解析:type t_string is table of varchar2(32767) index by binary_integer
@ 理解一: table 相当于是数组,这里定义了一个数组类型t_string; INDEX BY BINARY_INTEGER这里是定义数组下标是整数,因为ORACLE中下标可以是字符串. VARC ...
- JavaScript学习日志(二):面向对象的程序设计
1,ECMAScript不像其他面向对象的语言那样有类的概念,它的对象与其他不同. 2,ECMAScript有两种属性:数据属性和访问器属性.([[]]这种双中括号表示属性为内部属性,外部不可直接访问 ...
- unix下的文件和目录详解以及操作方法
前言:unix下一切东西都是文件,一共有7种不同的文件,前一篇博客已经讲解的很清楚了,不懂的可以看看这里.当然,博主知道有些朋友比忙,没时间看,那我就简单点讲讲这7中文件都有哪些吧. 文件类型包括在s ...
- 新CCIE笔记之'口口相传'路由协议
//由于思科所有命令行中没有尖括号"<>"这样的关键字,所以本文中出现命令行中的尖括号中的内容均为注释提示信息,代表此处应该填入那一类数据. 请容许我将RIP和EIGR ...
- 201521123065《Java程序设计》第六周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 1.2 可选:使用常规方法总结其他上课内容. 1.publ ...
- 201521123079《Java程序设计》第2周学习总结
1. 本周学习总结 学会String类和StringBuilder类的一些用法. 学会使用码云管理代码,会将码云上的代码和本地仓库关联 2. 书面作业 Q1.使用Eclipse关联jdk源代码,并查看 ...
- backtrack 使用Tab键补全命令
刚安装个BackTrack5(基于Ubuntu)做安全测试,发现默认安全设置级别很高,连ssh服务默认都关闭,root下不能使用tab键补全命令,这个就真不方便了.原因是root的配置文件注释了三行脚 ...
- Java 课程设计 "Give it up"小游戏(团队)
JAVA课程设计 "永不言弃"小游戏(From :Niverse) 通过Swing技术创建游戏的登陆注册界面,使用mySQL数据库技术完成用户的各项信息保存和游戏完成后的成绩保存. ...
- 201521123042《Java程序设计》第11周学习总结
作业参考文件 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同 ...
- 多线程:深入Thread.sleep
一直都说,Threed.sleep是不会释放锁,而wait是释放锁的(对象锁),现理论上来分析一下. 由于CPU分配的每个线程的时间片极为短暂(一般为几十毫秒),所以,CPU通过不停地切换线程执行,这 ...