Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
谁能告诉这段代码为什么错了?自己运动结果正常,为什么submit就wrong result呢#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator