跳到正文

题解

题解 P3187 【[HNOI2007]最小矩形覆盖】

江之永矣约 1 分钟
原文
文章信息与版本

文章信息

发布
2016年9月17日
收录
2025年12月12日
更新
2026年11月12日
篇幅
约 1 分钟
获赞
22
题目
P3187

版本

  1. v1当前

单调栈

下贴代码

C++
#include <stdio.h>
int main(){
    int n;
    long long x,y;
    int ans;
    long long stack[250001];
    int top=0;
    scanf("%d",&n);
    ans=n;
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&x,&y);
        while(top&&stack[top]>=y){
            if(stack[top]==y)
                ans--;
            top--;
        }
        stack[++top]=y;
    }
    printf("%d",ans);
        return 0;
}
原文
存档评论30 条抓取于