bzoj1113: [Poi2008]海报PLA

时间:2024-05-02 12:03:38
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 250005
using namespace std; int n,top,stack[maxn],ans; int main(){
int u,v;
scanf("%d",&n);
top=ans=,memset(stack,,sizeof(stack));
for (int i=;i<=n;i++){
scanf("%d%d",&u,&v);
while (top&&stack[top]>v) top--;
stack[++top]=v;
if (stack[top]!=stack[top-]) ans++;
}
printf("%d\n",ans);
return ;
}

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1113

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

做法:思路题,这题显然只与高有关,如果有两个矩阵的高相等,并且他们之间的矩阵的高都不小于他们的高,这样他们两个矩阵就只需要用一个海报来cover了。

所以我们可以用高效的单调栈来维护。