题目链接:

https://www.lydsy.com/JudgeOnline/problem.php?id=1113

题目大意:

N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们.

思路:

直接维护一个递增的单调栈,注意如果栈顶元素和当前值相同,那么当前值不加入栈中。

 #include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
#define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Mem(a) memset(a, 0, sizeof(a))
#define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
#define MID(l, r) ((l) + ((r) - (l)) / 2)
#define lson ((o)<<1)
#define rson ((o)<<1|1)
#define Accepted 0
#pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
typedef long long ll;
const int maxn = + ;
const int MOD = ;//const引用更快,宏定义也更快
const int INF = 1e9 + ;
const double eps = 1e-; stack<int>q;
int main()
{
int n, ans = , x, y;
scanf("%d", &n);
for(int i = ; i <= n; i++)
{
scanf("%d%d", &x, &y);
while(!q.empty() && q.top() > y)
{
q.pop();
ans++;
}
if(!q.empty() && q.top() == y)continue;
q.push(y);
}
ans += q.size();
printf("%d\n", ans);
return Accepted;
}

最新文章

  1. Python3基础 访问列表指定索引值的元素
  2. 《锋利的jQuery》(第2版)读书笔记4
  3. jQuery操作Table tr td常用的方法
  4. jquery-ui-处理拖动位置Droppable,Draggable
  5. html5 简单音乐播放器
  6. rsync+sersync实现文件实时同步
  7. 在CentOS上编译安装PostgreSQL
  8. poj 3130 How I Mathematician Wonder What You Are!
  9. angular在ie8下的一个bug
  10. UV印刷
  11. git 使用过程(四、回退版本)
  12. NioSocket相关知识
  13. Django_注册全局消息
  14. javascript 事件基础
  15. 如何在Visual Studio 2017中使用C# 7+语法
  16. 微信小程序支付,带java源码
  17. JAVA中final修饰符小结
  18. 合并数组,改变原数组apply与不改变原数组
  19. pytorch使用tensorboardX进行loss可视化
  20. CAD二次开发起步

热门文章

  1. 记一次Java AES 加解密 对应C# AES加解密 的一波三折
  2. SQL SERVER中LIKE使用变量类型输出结果不同
  3. 微信小程序入门篇
  4. JS 随机排序算法
  5. async和await学习笔记
  6. github小白上传本地代码及更新代码到GitHub及华为云教程
  7. SSM(一):spring-ioc
  8. 十分钟搞定mac下的phpstorm增加xdebug调试
  9. Codeforces841B
  10. Vue: ES6常用语法