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 ...
随机推荐
- Linux使用远程X Server显示图形
背景 通常我们不希望在服务器上安装图形界面,但有时候有些程序需要图形界面,比如安装oracle的时候.此时,可以配置让Linux使用远程的X Server进行图形界面显示. 首先要明确的是Linux ...
- linux下操作mysql
有关mysql数据库方面的操作,必须首先登录到mysql中. 开启MySQL服务后,使用MySQL命令可以登录.一般使用mysql -uroot -p即可.如果数据库不是本机,则需要加参数,常用参数如 ...
- java 运行时常量、编译时常量、静态块执行顺序
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt223 常量是程序运行时恒定不变的量,许多程序设计语言都有某种方法,向编译器告 ...
- 微信小程序swiper标签的测试
swiper属性(具体看官方文档): 一:testswiper.wxml的代码如下.testswiper.js自动生成示例代码. //testswiper.wxml <view > < ...
- 201521123034《Java程序设计》第七周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 ArrayList代码分析 1.1 解释ArrayList的contains源代码 答:从ArrayList ...
- 201521123039 《java程序设计》第七周学习总结
1. 本周学习总结 2. 书面作业 ArrayList代码分析 1.1 解释ArrayList的contains源代码 答:ArrayList的Contains的源码如上图所示,如果o为null,那么 ...
- 201521123044 《Java程序设计》第4周学习总结
1. 本章学习总结 2. 书面作业 1. 注释的应用 使用类的注释与方法的注释为前面编写的类与方法进行注释,并在Eclipse中查看.(截图) 答: 2. 面向对象设计(大作业1,非常重要) 2.1 ...
- [转载]Eclipse自定义快捷键导出和导入方法
背景: 以前做C/C++开发,习惯了Visual Studio这个强大的IDE,转到安卓开发后,用到蛋疼的Eclipse,实在不习惯,而且以前总觉得VS不流畅,现在才知道VS很好,才知道什么是真正的& ...
- 201521123025《java程序设计》第12周学习总结
#1. 本周学习总结 #2. 书面作业 将Student对象(属性:int id, String name,int age,double grade)写入文件student.data.从文件读出显示. ...
- Java课程设计 猜数游戏个人博客
1.团队课程设计博客链接 http://www.cnblogs.com/tt1104/p/7064349.html 2.个人负责模块或任务说明 1.成绩排行榜算法的设计: 2.排行榜存放到文件中, 3 ...