題目簡述:N個矩形,排成一排. 現在希望用盡量少的矩形海報Cover住它們。不能超出邊界.
emm 殘缺的知識點。。長度顯然沒什麼用。 寬度考慮單調遞增的情況,每多一個就加一個。如果新來一個矮的且高度在之前出現過,答案不變。如果再新來一個比剛加入的矮的 高一些的 且也出現過,答案還是要+1。
這個過程可以用單調棧維護單調遞增的序列,如果其中有那個元素答案不變,否則+1.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=3e5+5;
int sta[MAXN],top=0,n,ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int t1,t2;
scanf("%d%d",&t1,&t2);
while(top&&sta[top]>t2)top--;
if(sta[top]==t2)continue;
else sta[++top]=t2,ans++;
}
printf("%d\n",ans);
return 0;
}