//5_4_4: City Skyline 根据楼的叠加效果求楼的数量 POJ3044
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 50000 + 10;
const int maxh = 25000 + 10;
int main()
{
int i,x,N,W,top = 0,cnt = 0,a[maxn],stack[maxh];
scanf("%d%d",&N,&W);
for(i = 0;i < N;i ++) scanf("%d%d",&x,&a[i]);
a[N] = stack[top] = 0;
for(i = 0;i <= N;i ++)
{
while(top > -1)
{
if(a[i] > stack[top])
{
stack[++top] = a[i];
break;
}
else if(a[i] == stack[top]) break;
else if(a[i] < stack[top])
{
cnt ++;
top --;
}
}
}
printf("%d\n",cnt);
return 0;
}
/*测试结果:通过POJ3044检测
10 26
1 1
2 2
5 1
6 3
8 1
11 0
15 2
17 3
20 2
22 1
6
请按任意键继续. . .
*/
POJ3044 City Skyline
最新推荐文章于 2018-07-29 18:10:29 发布