BZOJ 1651 [Usaco2006 Feb]Stall Reservations 专用牛棚:优先队列【线段最大重叠层数】
2024-10-20 03:37:51
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651
题意:
给你n个线段[a,b],问你这些线段重叠最多的地方有几层。
题解:
先将线段按左端点a升序排序。
开一个优先队列q(升序排序),里面存线段的右端点b。
枚举线段i,然后:
(1)将q中所有小于a[i]的元素弹出。
(2)插入b[i]。
(3)更新ans = max(ans,q.size())
AC Code:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#define MAX_N 50005 using namespace std; int n;
int ans=;
pair<int,int> p[MAX_N];
priority_queue<int,vector<int>,greater<int> > q; int main()
{
cin>>n;
for(int i=;i<n;i++)
{
cin>>p[i].first>>p[i].second;
}
sort(p,p+n);
for(int i=;i<n;i++)
{
while(!q.empty() && q.top()<p[i].first) q.pop();
q.push(p[i].second);
ans=max(ans,(int)q.size());
}
cout<<ans<<endl;
}
最新文章
- Oracle 数据库特殊查询总结
- Java实现颜色渐变效果
- Maven进价:Maven构建错误汇总
- 三种对话框的示例(alert,confirm,prompt)
- Slickflow.NET 开源工作流引擎基础介绍(二) -- 引擎组件和业务模块的交互
- Android短信彩信收发流程(应用层)
- PHP截取字符串,获取长度,获取字符位置的函数
- angular 按需加载
- .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index";的问题
- iOS开发 调用系统相机和相册
- Tomcat源码调试环境搭建
- linux 基础(一)
- 使用第三方插件Gear Tacks 画齿轮
- 从零开始一起学习SLAM | 点云平滑法线估计
- CentOS 7系统查看系统版本和机器位数
- iOS 9: UIStackView入门
- 【转】Linux删除文件未释放空间问题处理
- PLSQL Develope连接oracle数据库配置
- xp 专业版组策略只有系统组件
- Python进阶-函数默认参数
热门文章
- 【日常学习】【并查集+map】codevs2639 约会计划题解
- Ubuntu下安装JDK图文解析
- 浅谈js中的MVC
- [转]如何用C++实现一个LRU Cache
- linux配置nfs步骤及心得
- IOS研究之网络编程(二)-Cocoa Streams使用具体解释
- android之Context对各种服务的管理
- canvas drawImage方法不显示图片的解决方案
- Java的Executor框架和线程池实现原理
- javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: