CodeForces 612D The Union of k-Segments
来源:互联网 发布:五子棋c语言判断胜负 编辑:程序博客网 时间:2024/05/17 07:04
题意:
给你一堆区间,然后让你把覆盖k次及k次以上的区间都输出出来
思路:
直接暴力扫分界点就好了
分界点是正向覆盖k次的就加进左端点,是反向,就加进右端点,然后输出就好了
#include<bits/stdc++.h>using namespace std;#define maxn 3000006pair<int,int> Line[maxn];int tot = 1;int t[maxn];int main(){ int n,k;scanf("%d%d",&n,&k); for(int i=0;i<n;i++) { int x,y;scanf("%d%d",&x,&y); Line[tot++]=make_pair(x,-1); Line[tot++]=make_pair(y,1); } sort(Line+1,Line+tot); int flag1 = 0,flag2 = 0; vector<int> ans1; vector<int> ans2; for(int i=1;i<tot;i++) { t[i] = t[i-1] - Line[i].second; if(t[i]==k&&t[i-1]==k-1) ans1.push_back(Line[i].first); } memset(t,0,sizeof(t)); for(int i=1;i<tot;i++) { t[i] = t[i-1] - Line[i].second; if(t[i]==k-1&&t[i-1]==k) ans2.push_back(Line[i].first); } if(ans1.size()!=ans2.size()) ans2.push_back(Line[tot-1].first); cout<<ans1.size()<<endl; for(int i=0;i<ans1.size();i++) cout<<ans1[i]<<" "<<ans2[i]<<endl;}
0 0
- 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 Educational Codeforces Round 4 D. The Union of k-Segments 离散化+map
- codeforces 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 612 D. The Union of k-Segments (非递归线段树+离散化)
- Educational Codeforces Round 4 612D The Union of k-Segments(stl)
- ★codeforces 612D The Union of k-Segments (思维or类扫描线)
- codeforces 612D The Union of k-Segments (前缀和处理区间)
- CodeForces 612D The Union of k-Segments(排序+区间计数、扫描线)
- The Union of k-Segments CodeForces
- The Union of k-Segments CodeForces
- 数据结构的二叉链表中序遍历
- hdu1061Rightmost Digit
- (转载)Python学习–数据分析路线
- 从程序员到CTO的Java技术路线图
- 【递推】【NOIP模拟】彩灯的问题 Lights
- CodeForces 612D The Union of k-Segments
- 一个关于类数组中如何使用new
- android studio 添加第三方jar
- 软件工程3
- Pinot中的Inverted Index源码分析
- 乌云章华鹏:如何构建高效的安全运维服务平台
- android toast使用总结
- poj 3273 Monthly Expense
- 后续_Learn Java for Android Development (第三版)