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 ...
随机推荐
- netlink+netfilter
http://blog.chinaunix.net/uid-21768364-id-3618377.html
- 霍夫变换(hough transform)
x-y轴坐标:y=kx+b k-b轴坐标:b=-xk+y θ-r轴坐标:
- java中字符串String 转 int(转)
java中字符串String 转 int String -> int s="12345"; int i; 第一种方法:i=Integer.parseInt(s); 第二种方法 ...
- jQuery ajax的traditional参数的作用
一般的,可能有些人在一个参数有多个值的情况下,可能以某个字符分隔的形式传递,比如页面上有多个checkbox: ? 1 2 3 4 5 6 $.ajax{ url:"xxxx&q ...
- fstream对象重复使用时注意clear()的调用
fstream对象重复使用时注意clear()的调用,否则会造成打开第二个文件失败.这是因为一个fstream对象对应磁盘上的一个文件,这种绑定关系在调用open()函数或者构造函数时指定,但有时我们 ...
- VBS数组函数学习实例分析
Array 函数 返回包含数组的Variant. Array(arglist) 参数:arglist是赋给包含在Variant中的数组元素的值的列表(用逗号分隔).如果没有指定此参数,则将会创建零长度 ...
- UIScrollView缩放图片操作
要想ScrollView缩放,必须告诉缩放那个控件,它自身的大小是不会缩放的: 并且ScrollView只能缩放自己内部的子控件: 1:这时就要用到代理,代理告诉ScrollView缩放哪个控件.(设 ...
- messager(消息窗口)
一.$.messager.alert()类似js中的alert('String') 方法参数:title, msg, icon, function(回调函数) 描述:title头部面板标题.msg主要 ...
- xml基础学习笔记02
接着上次的xml笔记01 ,记录一下如何DOM创建xml 一.由于没有特意来写博客,都是在程序中用注释的方法记录笔记,整理过来难免格式错误,排版什么的,大家好事看不懂就仔细看给出的代码加上注释,一定会 ...
- Careercup - Google面试题 - 5085331422445568
2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...