传送门

题目大意

给定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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Linq无聊练习系列6--Any/All/Contains/Concat/Union/Intersect/Except/take/skip/SqlMethods操作练习

    /*********************Any/All/Contains/Concat/Union/Intersect/Except/take/skip/SqlMethods操作练习******* ...

  4. 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 ...

  5. Educational Codeforces Round 4

    612A - The Text Splitting    20171121 简单字符串处理题 #include<stdlib.h> #include<stdio.h> #inc ...

  6. 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)

    原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解    By 岩之痕 目录: 一:综述 ...

  7. 1、SQL Server自动化运维 - 备份(一)业务数据库

    为了能够恢复数据,数据库运维基础就是备份,备份自动化也是运维自动化首要进行的. 笔者的备份自动化,通过配置表快速配置为前提,同时记录备份过程,尽可能的减少人工操作.首先将SQL Server备份按用途 ...

  8. BZOJ 4569 萌萌哒

    题目传送门 4569: [Scoi2016]萌萌哒 Time Limit: 10 Sec Memory Limit: 256 MB Submit: 483 Solved: 221 [Submit][S ...

  9. SQL函数

    1,字符串截取拼接 CONCAT(),'****');SUBSTRING_INDEX(c.context,'}',1);SUBSTRING_INDEX(a.task_context,':',-1) a ...

随机推荐

  1. hdu-2544-最短路(Bellman-Ford算法模板)

    题目链接 题意很清晰,入门级题目,适合各种模板,可用dijkstra, floyd, Bellman-ford, spfa Dijkstra链接 Floyd链接 Bellman-Ford链接 SPFA ...

  2. New Concept English three (57)

    28w/m 54errors I stopped to let the car cool off and to study the map. I had expected to be near my ...

  3. 用php实现斐波那契数列

    //1 1 2 3 5 8 13 ....//观察数列 你会发现下一个数是如何得来的 //  f(3) = f(2) + f(1)      f(4)=f(3)+f(2)           f(18 ...

  4. Phong光照模型的Shader实现

    计算反射向量 Phong用到的是反射向量,计算反射向量的公式是 R = 2*N(dot(N, L)) - L 这个公式是根据向量的投影公式以及平行四边形法则推导出来的 详细步骤请看这篇文章,讲的非常好 ...

  5. 关于C语言字符串函数使用的一点心得

    就字符串的拼接函数为例strcat. 原型:extern char *strcat(char *dest,char *src);用法:#include <string.h> 功能:把src ...

  6. 修改windows文件的换行符

    应用场景: 在办公中,有可能存在,某些命令脚本使用windows下的文本编辑器进行编写 当放到测试环境的Linux中时,运行报错 需要使用的软件:xxd hexdump  dos2unix 1.运行w ...

  7. java中初始化方法

    本文主要是讲从<java编程思想>中看到的东西,是第七章复用类的开头内容,主要是类初始化的几种方法的位置,主要包括 1.在定义对象的地方.这意味着他们总是在构造器被调用前被初始化. 2.在 ...

  8. ORA-12514: TNS: no listener 解决方案

    服务端:oracle 11g 客户端: pl/sql 问题描述: 用客户端 pl/sql 连接登录的时候,提示 "ORA-12514: TNS: no listener". 在服务 ...

  9. 聊聊基于Lucene的搜索引擎核心技术实践

    最近公司用到了ES搜索引擎,由于ES是基于Lucene的企业搜索引擎,无意间在“聊聊架构”微信公众号里发现了这篇文章,分享给大家. 请点击链接:聊聊基于Lucene的搜索引擎核心技术实践

  10. FileStream 常用的属性和方法

    FileStream常用的属性和方法 (转) 对流进行操作时要引用 using System.IO; 命名空间 FileStream常用的属性和方法: 属性: CanRead 判断当前流是否支持读取, ...