Cover
【题目描述】
有 N 个时间段,某个时间段可能包含其它时间段。
请找出能包含其它时间段最多的那个段,并计算出它包括的其它时间段有多少?
【数据范围】
1 <= N <= 25,000
1 <= 时间段开始和结束点 <= 2,000,000,000
【输入格式】
第1行:一个整数 N
第2..N+1行:第i+1行有两个整数A,B(1 <= A < B <= 2,000,000,000)表示第 i 个时间段的开始和结束端点。任意两个时间段的端点不相同。
【输出格式】
一行,一个整数。表示一段最多可包含的时间段数的最大值。
【样例输入】
4
1 7
2 3
5 6
4 10
【样例输出】
2
/*单调队列问题 按照左端点排一遍序
左端点简单入队 右端点分情况讨论
如果当前点Ti是右端点 并且与第一个时间点相匹配
则可以统计本段中的两端点都在期间的线段个数,并删除T1
删除T1之后如果T2的右端点已经出现过 T2可以继续删除
计数减一 因为他是T1-Ti的子段 不可能是最大解
不匹配时更加简单 计数+1 因为他一定是T1的子段
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct self {
int x,y;
bool operator < (const self &a) const{
return x<a.x;
}
}s[];
int t[],q[],head,tail,ans,n;
void work(){
head=tail=;
q[head]=;
for(int i=;i<=n;i++) {
bool update=;
while(s[q[head]].y<s[i].x&&head<=tail)head++;
for(int j=tail;j>=head;j--)
if(s[q[j]].y>s[i].y) {
update=;
t[q[j]]++;
ans=max(ans,t[q[j]]);
}
if(!update){
tail++;
q[tail]=i;
}
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&s[i].x,&s[i].y);
sort(s+,s+n+);
work();
cout<<ans<<endl;
return ;
}
Cover的更多相关文章
- Dancing Links and Exact Cover
1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...
- img及父元素(容器)实现类似css3中的background-size:contain / background-size:cover
img及父元素(容器)实现类似css3中的background-size:contain / background-size:cover <!DOCTYPE html> <html ...
- 集合覆盖 顶点覆盖: set cover和vertex cover
这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...
- poj 1266 Cover an Arc.
http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- HUST 1017 - Exact cover (Dancing Links 模板题)
1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...
- background-size的两个属性:cover和contain
两种都不会造成图片失真,其中: (1)cover:相当于宽度等于元素的宽度,高度设为auto: (2)contain:相当于高度等于元素的高度,宽度设为auto: 例如:设置一个高度和宽度都为300p ...
- Dancing Link --- 模板题 HUST 1017 - Exact cover
1017 - Exact cover Problem's Link: http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...
- CSS3 background-size 属性值:cover
当设置值为cover,可以呈现出图片铺满浏览器内容的视觉效果 实例 规定背景图像的尺寸: div { background:url(img_flwr.gif); background-size:80p ...
- background-size的cover和content的用法
background-size:cover; 表示背景图拉伸布满,如果在手机上做的话,背景图片会拉大,失真.这样做不妥 background-size:content; 表示背景图片在内容区域正常显示 ...
- 【英文】Bingo口语笔记(18) - Cover系列
cover charge 服务费 cover version 翻唱版本 cover the news 头条新闻
随机推荐
- NodeJS--exports和module.exports
继续迁移印象笔记中记录相关笔记,其实工作中遇到的很多问题当时解决了,后期就忘记了,多记录还是很有用的,好记性不如烂笔头嘛,以后要养成好习惯. NodeJS中 require 用来加载代码,而 expo ...
- nodejs 用户登录密码md5加密
jade文件 div.login ul.inp-content li span= '用户名:' input.ui-input1#input1(placeholder='请输入手机号') li sp ...
- elasticsearch 7 安装
elasticsearch 安装 操作系统:CentOS Linux release 7.4 elasticsearch:elasticsearch-7.1.1 es7+centos7 1.软件下载 ...
- MongDB之各种修改操作
接口IMongDaoUpdate: package com.net.test.mongdb.dao; import com.net.test.mongdb.entity.User; public in ...
- 科学计算库Numpy——文件读写
读文件 要读取的文件 有分隔符的文件 备注:delimiter分隔符. 有多余行的文件 备注:skiprows去掉几行. 指定列 备注:usecols指定使用哪几列. 写文件 保存后的文件 备注:fm ...
- python3.7 迭代器和生成器
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 迭代器和生成器 #迭代器协议: ''' 1.迭代器协议是指:对象 ...
- stark组件前戏(2)之单例模式
单,一个. 例,实例.对象. 通过利用Python模块导入的特性:在Python中,如果已经导入过的文件再被重新导入时候,python不会重新解释一遍,而是选择从内容中直接将原来导入的值拿来用. ...
- Codeforces Round #456 (Div. 2) B. New Year's Eve
传送门:http://codeforces.com/contest/912/problem/B B. New Year's Eve time limit per test1 second memory ...
- f触发器、存储过程
drop trigger trig_insert--删除触发器
- 阿里云服务器+Tomcat项目+mysql 发布项目全过程
这个博客管理系统折腾我好几天了. 总结一下整个过程吧! 1.首先这个博客在tomcat下 windows系统可以完全跑起来了,无论是前台或者后台都能实现所有的功能. 2.然后我买了一个域名jasonj ...