| ||||||||||
| 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 | |||||||||
Java 时间性能不好,测试过不了,哪位大神帮我看看import java.util.*;
public class Main
{
static int max = 0;
static int depthMax = 0;
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int aa = cin.nextInt();
int bb = cin.nextInt();
int height[][] = new int[aa][bb];
for (int i=0;i<aa;i++)
for (int j=0;j<bb;j++)
height[i][j] = cin.nextInt();
for (int i=0;i<aa;i++)
{
for (int j=0;j<bb;j++)
{
depthMax = 0;
next(height,i,j);
}
}
System.out.println(max);
}
public static void next(int[][] data,int a,int b)
{
if (max == data.length*data[a].length)
System.exit(0);
depthMax++;
if (goLeft(data,a,b))
next(data,a,b-1);
if (goRight(data,a,b))
next(data,a,b+1);
if (goUp(data,a,b))
next(data,a-1,b);
if (goDown(data,a,b))
next(data,a+1,b);
if (max < depthMax)
max = depthMax;
depthMax--;
}
public static boolean goLeft(int[][] data,int a,int b)
{
if (b<=0)
return false;
if (data[a][b-1] < data[a][b])
return true;
else return false;
}
public static boolean goRight(int[][] data,int a,int b)
{
if (b>=data[0].length-1)
return false;
if (data[a][b+1] < data[a][b])
return true;
else return false;
}
public static boolean goUp(int[][] data,int a,int b)
{
if (a<=0)
return false;
if (data[a-1][b] < data[a][b])
return true;
else return false;
}
public static boolean goDown(int[][] data,int a,int b)
{
if (a>=data.length-1)
return false;
if (data[a+1][b] < data[a][b])
return true;
else return false;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator