10.30 POJ 3494单调栈

http://poj.org/problem?id=3494
https://blog.csdn.net/zuzhiang/article/details/78136417

#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
ll read()
{
	char ch=' ';
	ll f=1;ll x=0;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
	    x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
const ll N=2100;
ll a[N];
ll l[N],r[N];
stack  s;
void init()
{
	while(!s.empty())
	{
		s.pop();
	}
}
int main()
{
	ll n,m;
	ll i,j;
	ll x;
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		ll ans=0;
		memset(a,0,sizeof(a));
		a[0]=-1;a[n+1]=-1;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				x=read();
				if(x==1)	a[j]+=1;
				else	a[j]=0;
			}
			init();
			for(j=1;j<=n+1;j++)
			{
				while(!s.empty()&&a[j]=0;j--)
			{
				while(!s.empty()&&a[j]

你可能感兴趣的:(版子,数据结构)