1683: [Usaco2005 Nov]City skyline 城市地平线
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 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
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
与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);
}