题目链接: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;
}

最新文章

  1. Oracle 数据库特殊查询总结
  2. Java实现颜色渐变效果
  3. Maven进价:Maven构建错误汇总
  4. 三种对话框的示例(alert,confirm,prompt)
  5. Slickflow.NET 开源工作流引擎基础介绍(二) -- 引擎组件和业务模块的交互
  6. Android短信彩信收发流程(应用层)
  7. PHP截取字符串,获取长度,获取字符位置的函数
  8. angular 按需加载
  9. .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index&quot;的问题
  10. iOS开发 调用系统相机和相册
  11. Tomcat源码调试环境搭建
  12. linux 基础(一)
  13. 使用第三方插件Gear Tacks 画齿轮
  14. 从零开始一起学习SLAM | 点云平滑法线估计
  15. CentOS 7系统查看系统版本和机器位数
  16. iOS 9: UIStackView入门
  17. 【转】Linux删除文件未释放空间问题处理
  18. PLSQL Develope连接oracle数据库配置
  19. xp 专业版组策略只有系统组件
  20. Python进阶-函数默认参数

热门文章

  1. 【日常学习】【并查集+map】codevs2639 约会计划题解
  2. Ubuntu下安装JDK图文解析
  3. 浅谈js中的MVC
  4. [转]如何用C++实现一个LRU Cache
  5. linux配置nfs步骤及心得
  6. IOS研究之网络编程(二)-Cocoa Streams使用具体解释
  7. android之Context对各种服务的管理
  8. canvas drawImage方法不显示图片的解决方案
  9. Java的Executor框架和线程池实现原理
  10. javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: