POJ3044 City Skyline

本文探讨了如何通过楼的叠加效果求出楼的数量,并应用此方法解决POJ3044问题,涉及算法优化与城市天际线的数学建模。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//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
请按任意键继续. . .
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值