Educational Codeforces Round 4 D. The Union of k-Segments 排序
You re 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,问你有k跳线段以上相交的线段有多少
题解:按照 左右端点区分,x,y一起排序,找增加至k个左端点加入左答案,减少到k-1个端点加入右答案,注意一个点的线段
- //meek
- ///#include<bits/stdc++.h>
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <queue>
- #include <map>
- #include <set>
- #include <stack>
- #include <sstream>
- #include <queue>
- using namespace std ;
- typedef long long ll;
- #define mem(a) memset(a,0,sizeof(a))
- #define pb push_back
- #define fi first
- #define se second
- #define MP make_pair
- inline ll read()
- {
- ll x=,f=;
- char ch=getchar();
- while(ch<''||ch>'')
- {
- if(ch=='-')f=-;
- ch=getchar();
- }
- while(ch>=''&&ch<='')
- {
- x=x*+ch-'';
- ch=getchar();
- }
- return x*f;
- }
- //****************************************
- const int N=+;
- const ll INF = 1ll<<;
- const int inf = ;
- const int mod= ;
- int n,k,x,y,t[N];
- pair<int,int> Line[N];
- vector<int >ans1,ans2;
- int main() {
- scanf("%d%d",&n,&k);
- int cnt = ;
- for(int i=;i<=n;i++) {
- scanf("%d%d",&x,&y);
- Line[cnt++] = MP(x,-);
- Line[cnt++] = MP(y,);
- }
- sort(Line+,Line+cnt);
- for(int i=;i<cnt;i++)
- {
- t[i] = t[i-] - Line[i].se;
- if(t[i]==k&&t[i-]==k-)
- ans1.pb(Line[i].fi);
- }
- memset(t,,sizeof(t));
- for(int i=;i<cnt;i++)
- {
- t[i] = t[i-] - Line[i].se;
- if(t[i]==k-&&t[i-]==k)
- ans2.pb(Line[i].fi);
- }
- if(ans1.size()!=ans2.size()) ans2.pb(Line[cnt-].fi);
- cout<<ans1.size()<<endl;
- for(int i=;i<ans1.size();i++)
- cout<<ans1[i]<<" "<<ans2[i]<<endl;
- return ;
- }
代码
Educational Codeforces Round 4 D. The Union of k-Segments 排序的更多相关文章
- 【扫描线】Educational Codeforces Round 4 D. The Union of k-Segments
http://codeforces.com/contest/612/problem/D [题解] http://blog.csdn.net/strokess/article/details/52248 ...
- Educational Codeforces Round 5
616A - Comparing Two Long Integers 20171121 直接暴力莽就好了...没什么好说的 #include<stdlib.h> #include&l ...
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
随机推荐
- windows phone版的一个儿教app
昨天下午看见一个园友写的一篇关于儿教的api,看了也就两三个接口,所以数据处理应该不会太复杂,主要是界面的效果,要求可能比较高.于是我就重新自己写了一个app,实现很简单,花的时间比较多的地方应该是在 ...
- IOS中的UINavigationController(导航控制器)
UINavigationController UINavigationControlle:导航控制器,是iOS中最常用的多视图控制器之一,它用来管理多个试图控制器 导航控制器可以认为是管理控制器的控制 ...
- JS如何获取多个相同class标签并分别再输出各自的文本
function getClass(boo) { var span = $("span.w");//获取所有的span标签 <span class="w" ...
- Python实现nb(朴素贝叶斯)
Python实现nb(朴素贝叶斯) 运行环境 Pyhton3 numpy科学计算模块 计算过程 st=>start: 开始 op1=>operation: 读入数据 op2=>ope ...
- To add private variable to this Javascript literal object
You can use number as function/variable name, the numberic name can't be accessed from parent scope, ...
- Valuable site on github
https://thegrid.io/?utm_source=adwords&utm_medium=cpc&utm_campaign=thegrid-display-english&a ...
- 20145103 《Java程序设计》第3周学习总结
20145103 <Java程序设计>第3周学习总结 教材学习内容总结 第四章我首先了解了CPU与内存的关系,栈与堆的关系.要产生对象必须先定义类,类是对象的设计图,对象是累的实例.以类名 ...
- Mysql数据库表排序规则不一致导致联表查询,索引不起作用问题
Mysql数据库表排序规则不一致导致联表查询,索引不起作用问题 表更描述: 将mysql数据库中的worktask表添加ishaspic字段. 具体操作:(1)数据库worktask表新添是否有图片字 ...
- eclipse中设置中文javadoc+如何查看class的中文javadoc
一. eclipse中设置中文javadoc 1.先到http://download.java.net/jdk/jdk-api-localizations/jdk-api-zh-cn/publish ...
- Kali Linux 命令集
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...