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 ...
随机推荐
- android开发系列之6*0.9不等于5.4
昨天晚上我们客户端平台上面曝出了一个很奇诡的bug,那就是本来在客户端里面有个商品买6元,但是因为碰巧赶上打9折,这个时候我们很自然的处理就是6*0.9.好吧你以为so easy的事情,其实就出错了, ...
- HTTP网页错误代码大全带解释
HTTP网页错误代码大全带解释 HTTP 400 - 请求无效HTTP 401.1 - 未授权:登录失败HTTP 401.2 - 未授权:服务器配置问题导致登录失败HTTP 401.3 - ACL 禁 ...
- Jni中C++和Java的参数传递
Jni中C++和Java的参数传递 如何使用JNI的一些基本方法和过程在网上多如牛毛,如果你对Jni不甚了解,不知道Jni是做什么的,如何建立一个基本的jni程序,或许可以参考下面下面这些文章:利用V ...
- git的初步使用
1.在GitHub上建立项目登录GitHub后,你可以在右边靠中那里找到一个按钮“New Repository”,点击过后,填入项目名称.说明和网址过后就可以创建了,然后会出现一个提示页面,记下类似g ...
- php xml转为xml或者json
<?php class XmlToArray { private $xml; private $contentAsName="content" ; private $attr ...
- R 语言中文乱码问题
R 语言似乎在WINDOWS平台上对中文的支持不是特别好,似乎是3.1.2的一个BUG. 目前我研究出了一个临时解决方案,你可以将代码编写成一个函数,从而在调用的过程中不必如下繁琐: 1. 先将本地语 ...
- Java Day 09
子父类的构造函数 在子类的构造函数中,第一行有一个默认的隐式语句:super() 子类的实例化过程:子类中所有的构造函数默认都会访问父类中的空参数的构造函数. 为什么子类实例化的时候要访问父类中的构造 ...
- unity工具IGamesTools之批量生成帧动画
unity工具IGamesTools批量生成帧动画,可批量的将指定文件夹下的帧动画图片自动生成对应的资源文件(Animation,AnimationController,Prefabs) unity工 ...
- java读取资源文件
ResourceBundle bundle = ResourceBundle.getBundle("cn.liuning.resource.MessageResource"); b ...
- javascript各种模式解析
1.工厂模式: 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程(后面还将讨论其他设计模式及其在JavaScript 中的实现).考虑到在ECMAScript 中无法创建 ...