bzoj 1683: [Usaco2005 Nov]City skyline 城市地平线

1683: [Usaco2005 Nov]City skyline 城市地平线

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 294  Solved: 247
[ Submit][ Status][ Discuss]

Description

Input

   第1行:2个用空格隔开的整数N和W.

    第2到N+1行:每行包括2个用空格隔开的整数x,y,其意义如题中所述.输入中的x严格递增,并且第一个z总是x.

Output

    输出一个整数,表示城市中最少包含的建筑物数量.

Sample Input

10 26
1 1
2 2
5 1
6 3
8 1
11 0
15 2
17 3
20 2
22 1

INPUT DETAILS:

The case mentioned above

Sample Output

6

HINT

Source

[ Submit][ Status][ Discuss]
题解:单调栈。

与bzoj 1113 类似。

#include<iostream>  
#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<algorithm>  
#define N 550003  
using namespace std;  
int n,m,ans;  
int a[N],st[N],b[N];  
int main()  
{  
    scanf("%d%d",&n,&m);  
    int num=0;
    for (int i=1;i<=n;i++) 
     scanf("%d%d",&a[i],&b[i]);  
    int top=0;  st[++top]=0;
    for (int i=1;i<=n;i++)  
     {  
        while(b[i]<=st[top]&&top)  
         {  
            if(b[i]==st[top]) ans++;  
            top--;   
         }   
        st[++top]=b[i];  
     }  
    printf("%d\n",n-ans);  
}  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值