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

谁能告诉这段代码为什么错了?自己运动结果正常,为什么submit就wrong result呢

Posted by zhuyunxiang1984 at 2011-02-03 23:46:42 on Problem 1088
#include <iostream>
using namespace std;

int g_nWidth = 0;
int g_nHeight = 0;
int g_pArray[100][100];
int g_nMaxStep = 0;

void func(int x, int y, int nStep)
{
	if(nStep > g_nMaxStep)
	{
		g_nMaxStep = nStep;
	}
	if( x + 1 < g_nWidth && g_pArray[x+1][y] < g_pArray[x][y] )
	{
		func( x + 1, y, nStep + 1 );
	}
	if( x - 1 >= 0 && g_pArray[x-1][y] < g_pArray[x][y] )
	{
		func( x - 1, y, nStep + 1 );
	}
	if( y + 1 < g_nHeight && g_pArray[x][y+1] < g_pArray[x][y] )
	{
		func( x, y + 1, nStep + 1 );
	}
	if( y - 1 >= 0 && g_pArray[x][y-1] < g_pArray[x][y] )
	{
		func( x, y - 1, nStep + 1 );
	}
}

int main()
{
	cin>>g_nWidth>>g_nHeight;
	for( int i = 0; i < g_nHeight; ++i )
	{
		for( int j = 0; j < g_nWidth; ++j )
		{
			cin>>g_pArray[j][i];
		}
	}
	//找出最高点索引
	int nX = 0;
	int nY = 0;
	for( int i = 0; i < g_nHeight; ++i )
	{
		for( int j = 0; j < g_nWidth; ++j )
		{
			if( g_pArray[nY][nX] < g_pArray[j][i] )
			{
				nX = i;
				nY = j;
			}
		}
	}
	func(nX,nY,1);
	cout<<g_nMaxStep<<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