首页 > 其他 > 详细

POJ 3250 Bad Hair Day 单调栈

时间:2014-10-15 21:14:32      阅读:245      评论:0      收藏:0      [点我收藏+]

维护一个单调递减的栈 每次家进栈首的牛必定可以被其他栈里面的牛看到

#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 80010;
typedef unsigned long long LL;
int a[maxn], s[maxn];
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int top = 0;
	LL ans = 0;
	for(int i = 1; i <= n; i++)
	{
		while(top && a[i] >= a[s[top]])
			top--;
		ans += top;
		s[++top] = i;
	}	
	printf("%llu\n", ans);
	return 0;
}


POJ 3250 Bad Hair Day 单调栈

原文:http://blog.csdn.net/u011686226/article/details/40116219

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!