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