Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贡献一下我的代码,加了一圈围墙,逻辑上可以简单一点

Posted by hsmwzj at 2010-08-05 23:13:24 on Problem 1088
#include <iostream>
using namespace std;

int arr[102][102];//加一圈围墙,数据之外都是10001
int height[101][101];

int CountHeight(int x,int y)
{
	int MaxArround = 0;
	if(height[x][y]) 
		return height[x][y];
	if(arr[x][y]>arr[x-1][y])
		if(MaxArround<CountHeight(x-1,y))
			MaxArround=CountHeight(x-1,y);
	if(arr[x][y]>arr[x+1][y])
		if(MaxArround<CountHeight(x+1,y))
			MaxArround=CountHeight(x+1,y);
	if(arr[x][y]>arr[x][y-1])
		if(MaxArround<CountHeight(x,y-1))
			MaxArround=CountHeight(x,y-1);
	if(arr[x][y]>arr[x][y+1])
		if(MaxArround<CountHeight(x,y+1))
			MaxArround=CountHeight(x,y+1);
	return height[x][y] = MaxArround+1;
} 

int main()
{
	int r,c;
	cin>>r>>c;
	int i,j;
	for(i=0;i<102;i++)
		for(j=0;j<102;j++)
			arr[i][j]=10001;
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
		{
			cin>>arr[i][j];
			height[i][j]=0;
		}
	for(i=1;i<=r;i++)
		for(j=1;j<=c;j++)
			CountHeight(i,j);
	for (i=1;i<=r;i++)
		for (j=1;j<=c;j++)
			if (height[1][1] < height[i][j])
			{
				height[1][1] = height[i][j];
			}	
	cout<<height[1][1]<<endl;
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator