Codeforces 612D The Union of k-Segments
来源:互联网 发布:淘宝开店货源哪来 编辑:程序博客网 时间:2024/05/16 12:03
传送门:
http://codeforces.com/contest/612/problem/D
题意:找线段的集合,使得其中包含满足下个性质的点:
点属于至少k条线段
题解:排序,左端点标-1,右端点标1,然后O(2*n)扫描一遍点,开个计数器记录当前点属于多少条线段,然后记录下来所有满足条件的线段左右端点即可
code:
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+10;int n,k;vector<pair<int,int> >v;vector<pair<int,int> >ans;int l,r;int main(){ v.clear(); scanf("%d%d",&n,&k); for(int i=0;i<n;i++) { scanf("%d%d",&l,&r); v.push_back(make_pair(l,-1)); v.push_back(make_pair(r,1)); } sort(v.begin(),v.end()); int c=0; for(int i=0;i<2*n;i++) { c-=v[i].second; if(v[i].second==-1&&c==k) l=v[i].first; if(v[i].second==1&&c==k-1) ans.push_back(make_pair(l,v[i].first)); } printf("%d\n",ans.size()); for(int i=0;i<ans.size();i++) { printf("%d %d\n",ans[i].first,ans[i].second); } return 0;}
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
- SHell启动服务停止重启脚本模板
- 深度学习系列(九):详解工具箱参数及网络一种改进方式-dropout
- 全面薪酬制度的优势
- Docker的Web UI管理:shipyard+swarm-(手动)安装&试用
- eclipse部署java web项目到tomcat中
- Codeforces 612D The Union of k-Segments
- android Volley 上传文件上传图片
- 面试官立马淘汰的四类求职者
- 通过adb命令向Android模拟器中导入通讯录联系人
- Android M Launcher3主流程源码浅析
- 在创建线程时,必须要建立一个Thread类的或其子类的实例
- Python多线程学习
- VirtualBox安装
- 您相伴匆匆走过的三年,她是怎样的倔强