POJ 3494(可以过)

#include <iostream>
#include <stack>
#include <ctime>
using namespace std;

typedef struct point{
	int x,y;
} point;

int M,N;
int map[2000][2000];
int now[2000];
int res;
stack<point> sta;

void show(int count){
	for(int i = 0; i<=count; ++i){
		printf("%4d",now[i]);
	}
	printf("\n");
}

void solve(int count){	
	int high,temp,width;
	stack<point> sta;
	point p1,p2;
	p1.x = 1;
	high = p1.y = now[0];
	sta.push(p1);	
	for(int i = 1; i <= count; ++i){
		if(high < now[i]){
			p1.x = 1;
			high = p1.y = now[i];			
			sta.push(p1);
		}else{
			p1 = sta.top(); sta.pop();						
			if(p1.x * p1.y > res){
				res = p1.x * p1.y;				
			}			
			width = p1.x;
			if(sta.size()!=0){
				p1 = sta.top();
				high = p1.y;
			}else{
				high = 0;				
			}
						
			while(high >= now[i]){
				sta.pop();
				p1.x = p1.x + width;
				if(p1.x * p1.y > res){
					res = p1.x * p1.y;					
				}				
				width = p1.x;
				if(sta.size() != 0){
					p1 = sta.top();
					high = p1.y;
				}else{
					high = 0;
				}
			}			
			p1.x = 1 + width;		
			high = p1.y = now[i];
			sta.push(p1);
			
		}
	}
	width = 0;
	if(now[0] == 2 && now[1]==2 && now[2] == 1){
		p1 =sta.top();		
	}
		
	while(sta.size()){
		p1 = sta.top(); sta.pop();
		p1.x = p1.x + width;
		if(p1.x * p1.y > res){
			res = p1.x * p1.y;			
			
		}		
		width = p1.x;
	}
}

int main(){	
	clock_t start,finish;
	start=clock();
	freopen("a.txt","r",stdin);
	freopen("b.txt","w",stdout);
	int i,j,k,temp,count,t;
	while(scanf("%d %d",&M,&N) != EOF){
		for(i = 0; i < M; ++i){
			for(j = 0; j < N; ++j){
				scanf("%d",&map[i][j]);
			}		
		}
		for(i = 1; i < M; ++i){
			for(j = 0; j < N; ++j){
				if( map[i][j] == 1 && map[i-1][j]!=0){
					map[i][j] += map[i-1][j];
				}
			}
		}		
		res = 0;				
		for(i = 0; i < M; ++i){
			count = -1;
			for(j = 0; j < N; ++j){		
				if(map[i][j] != 0 ){
					now[++count] = map[i][j];
				}else if(count>=0){								
					solve(count);
					count = -1;
				}
			}
			if(count != -1){								
				solve(count);
			}
		}
		printf("%d\n",res);
	}
	finish=clock();
    cout << finish-start   << "/" << CLOCKS_PER_SEC  << " (s) "<< endl;
	return 0;	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值