612D The Union of k-Segments
题目大意
给定n个区间,问你被覆盖至少k次的区间(两端连续区间可以合并)最少有多少个,并输出。
分析
大水题呀QwQ,只需要将每个点的位置及它是左端点还是右端点这两个信息存起来然后进行一些简单操作就行了,详见代码。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
int tot,oul[],our[];
struct node {
int a,b;
};
bool operator < (const node x,const node y){
if(x.a==y.a)return x.b<y.b;
return x.a<y.a;
}
vector<node>b;
int main(){
int n,m,i,le,ri;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
scanf("%d%d",&le,&ri);
b.push_back({le,});
b.push_back({ri,});
}
sort(b.begin(),b.end());
int wl=,is=;
for(i=;i<(int)b.size();i++){
if(b[i].b==)wl++;
else wl--;
if(wl>=m&&!is)oul[++tot]=b[i].a,is=;
if(wl<m&&is)our[tot]=b[i].a,is=;
}
cout<<tot<<endl;
for(i=;i<=tot;i++)
printf("%d %d\n",oul[i],our[i]);
return ;
}
612D The Union of k-Segments的更多相关文章
- codeforces 612D The Union of k-Segments (线段排序)
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- Educational Codeforces Round 4 D. The Union of k-Segments 排序
D. The Union of k-Segments You re given n segments on the coordinate axis Ox and the number k. The ...
- Linq无聊练习系列6--Any/All/Contains/Concat/Union/Intersect/Except/take/skip/SqlMethods操作练习
/*********************Any/All/Contains/Concat/Union/Intersect/Except/take/skip/SqlMethods操作练习******* ...
- http://codeforces.com/contest/612/problem/D
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- Educational Codeforces Round 4
612A - The Text Splitting 20171121 简单字符串处理题 #include<stdlib.h> #include<stdio.h> #inc ...
- 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)
原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解 By 岩之痕 目录: 一:综述 ...
- 1、SQL Server自动化运维 - 备份(一)业务数据库
为了能够恢复数据,数据库运维基础就是备份,备份自动化也是运维自动化首要进行的. 笔者的备份自动化,通过配置表快速配置为前提,同时记录备份过程,尽可能的减少人工操作.首先将SQL Server备份按用途 ...
- BZOJ 4569 萌萌哒
题目传送门 4569: [Scoi2016]萌萌哒 Time Limit: 10 Sec Memory Limit: 256 MB Submit: 483 Solved: 221 [Submit][S ...
- SQL函数
1,字符串截取拼接 CONCAT(),'****');SUBSTRING_INDEX(c.context,'}',1);SUBSTRING_INDEX(a.task_context,':',-1) a ...
随机推荐
- 2018.7.2 AK22 不良品分析
a 电路 b 软件 STM32-工业炉温控制器程序 c . layout 不良分析: 1测各模块电压 12V ok 5V ok 3.3V ok 2跟换MCU 给MCU烧程序 ok 3测量MCU晶 ...
- 安装Aptana时检测不到已经安装的Nodejs
1.环境前提 已经安装了Git和Nodejs,在安装Aptana时任然提示如下错误: Failed to correctly acquire installer_nodejs_windows.msi ...
- CodeForces - 900D: Unusual Sequences (容斥&莫比乌斯&组合数学)
Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such ...
- Linux 修改PostgreSQL外部访问白名单
1. 查找配置文件 # find / -name pg_hba.conf # find / -name postgresql.conf 2.修改 2.1 修改pg_hba.conf 查找IPv4 lo ...
- 【模板】【学习笔记】noip数学
一.素数 欧拉筛 void prime(){ check[]=; ;i<=n;i++){ if(!check[i])prim[++cnt]=i;//这个if语句后面没有大括号!! ;j<= ...
- 自编jQuery插件实现模拟alert和confirm
现在绝大多数网站都不用自带的alert和confirm了,因为界面太生硬了.因此这个插件就这样产生了自己定制一个的想法...... 啥也不说,先上图,有图有真相 :) 现在绝大多数网站都不用自带的al ...
- java中I/O类
总结:输入流/输出流 方法,变量: package com.aini; //流类.输入输出流 import java.io.*; public class rtyeew {// (File file) ...
- 2016第十三届浙江省赛 D - The Lucky Week
D - The Lucky Week Edward, the headmaster of the Marjar University, is very busy every day and alway ...
- linux 学习2 常用命令
1.显示日期的指令: date 2. [Tab]按键---具有『命令补全』不『档案补齐』的功能 3: su和 sudo su用于用户之间的切换. su在不加任何参数,默认为切换到root用户 ...
- Java 的标识符
标识符: 在写代码的时候为了增强代码的阅读性会自定义很多名字,如:类名.方法名.变量名等 这种名称成为标识符 标识符命名规则: 由字母(可以是中文).数字.下划线.$ 组成,但不能以数字开头 大小写敏 ...