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 ...
随机推荐
- hdu-2544-最短路(dijkstra算法模板)
题目链接 题意很清晰,入门级题目,适合各种模板,可用dijkstra, floyd, Bellman-ford, spfa Dijkstra链接 Floyd链接 Bellman-Ford链接 SPFA ...
- 2.mysql优化---增删改优化
整理自互联网 补充知识点:操作数据语句优化的认识 通常情况下,当访问某张表的时候,读取者首先必须获取该表的锁,如果有写入操作到达,那么写入者一直等待读取者完成操作(查询开始之后就不能中断,因此允许读取 ...
- 畅通工程(自己写的BFS,但后面想了下并查集更好更快)
某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可). ...
- Element header-row-style设置多个属性
方式1: 直接在标签上添加上属性值: <el-table :header-cell-style="{background:'#F3F4F7',color:'#555'}" & ...
- Vue 将样式绑定到一个对象让模板更清晰
Vue 将样式绑定到一个对象让模板更清晰 <div id="app"> <div v-bind:style="styleObject"> ...
- bzoj 1607 [Usaco2008 Dec]Patting Heads 轻拍牛头——枚举倍数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1607 #include<iostream> #include<cstdio ...
- Mstar 编译器的搭建
机顶盒: 1.解压“mipsisa32-elf-3.4.4-20101123.i386linux.tar.gz" 应用编译器 2.mips-4.3-51-mips-linux-gnu-i68 ...
- JSF在ui:include中传递参数到对应控制层
在JSF中使用ui:include方法可以引入一个页面到当前页面中,如果要向被包含的页面中传入参数,可以使用ui:param标签,这个标签类似于f:param,只不过一个用于页面,一个用于实际标签.示 ...
- [C++] 贪心算法之活动安排、背包问题
一.贪心算法的基本思想 在求解过程中,依据某种贪心标准,从问题的初始状态出发,直接去求每一步的最优解,通过若干次的贪心选择,最终得出整个问题的最优解. 从贪心算法的定义可以看出,贪心算法不是从整体上考 ...
- Day2-VIM(一):移动
基础 字符移动 k 上移 k h 左移 h l l 右移 j j 下移 你也可以使用键盘上的方向键来移动,但这么做h j k l的存在就失去了意义 之所以使用h j k l来控制方向,其主要目的是让你 ...