Educational Codeforces Round 4 D. The Union of k-Segments(★)
来源:互联网 发布:swfobject.js 官网 编辑:程序博客网 时间:2024/05/17 08:05
题意:
给定n个区间,问你被覆盖至少k次的区间最少有多少个,并输出.
思路十分简洁,一个区间若被覆盖k次,则在这个区间前至少要出现k个线段的起点,且出现的起点减去终点数量不能小于k,这样排下序,线段起点+1,终点-1,判断下是否大于k一遍遍历下来就出答案了。
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cstdlib>#include <algorithm>#include <cmath>#include <vector>#include <set>#include <list>#include <queue>#include <map>#include <stack>using namespace std;#define L(i) i<<1#define R(i) i<<1|1#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-3#define maxn 2000010#define MOD 100000007struct node{ int val,flag; bool operator <(const node &a)const { return val < a.val || (val == a.val && flag < a.flag); }}a[maxn];int n,k,ans[maxn];int main(){ int t,c = 1; //scanf("%d",&t); while(scanf("%d%d",&n,&k) != EOF) { for(int i = 0; i < n; i++) { int x,y; scanf("%d%d",&x,&y); a[2*i].val = x; a[2*i].flag = 0; a[2*i+1].val = y; a[2*i+1].flag = 1; } sort(a,a+2*n); int cnt = 0,num = 0; for(int i = 0; i < 2*n; i++) { if(a[i].flag == 0) { cnt++; if(cnt == k) ans[num++] = a[i].val; } else { if(cnt == k) ans[num++] = a[i].val; cnt--; } } printf("%d\n",num/2); for(int i = 0; i < num; i+= 2) printf("%d %d\n",ans[i],ans[i+1]); } return 0;}
0 0
- Educational Codeforces Round 4 D. The Union of k-Segments
- Educational Codeforces Round 4-D. The Union of k-Segments
- Educational Codeforces Round 4 D. The Union of k-Segments(★)
- Codeforces 612D Educational Codeforces Round 4 D. The Union of k-Segments 离散化+map
- Educational Codeforces Round 4 612D The Union of k-Segments(stl)
- Educational Codeforces Round 4 D The Union of k-Segments (扫描线)
- codeforces D. The Union of k-Segments 排序
- Codeforces 612D The Union of k-Segments 【思维】
- Codeforces 612D The Union of k-Segments
- CodeForces 612 D. The Union of k-Segments(水~)
- codeforces 612D The Union of k-Segments (sorting)
- CodeForces 612D The Union of k-Segments
- CodeForces 612D - The Union of k-Segments(模拟)
- Codeforces 612D The Union of k-Segments
- ★codeforces 612D The Union of k-Segments (思维or类扫描线)
- The Union of k-Segments CodeForces
- The Union of k-Segments CodeForces
- Codeforces 612 D. The Union of k-Segments (非递归线段树+离散化)
- 堆排序
- xtrabackup原理
- Android中的电话通讯机制
- 查看显卡的计算能力
- TabHost--选项卡案例
- Educational Codeforces Round 4 D. The Union of k-Segments(★)
- 仅有正反馈的op或连正反馈都没有的op电路
- java之输出字符到java(或txt)文件
- Permutations
- PC上安装Qt-Embedded
- 1——PHP常见的系统常量
- HDU1710-Binary Tree Traversals
- JS实现无缝滚动
- Problem C - Sums ACM/ICPC Central Europe Regional Contest 2014