| ||||||||||
| 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 | |||||||||
无助啊,同样的算法,要翻译成c++代码才能过。java一直超时!谁能把这个java代码改ac???在不修改算法的前提下无助呀!!!
import java.util.Scanner;
/**
*
* @author taylor
*/
public class Main {
private static int[][] height = null;
private static int[][] distance = null;
private static int rowI = 0;
private static int colI = 0;
private static int ansI = 0;
private static boolean isAltered = false;
private static void deal(int forej, int forek, int j, int k){
if (forej < 0 || forej >= rowI) {
return;
}
if (forek < 0 || forek >= colI) {
return;
}
if (height[forej][forek] <= height[j][k]) {
return;
}
int tmpI = distance[forej][forek] + 1;
if (tmpI > distance[j][k]) {
distance[j][k] = tmpI;
isAltered = true;
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
rowI = in.nextInt();
colI = in.nextInt();
ansI = 1;
isAltered = false;
height = new int[rowI][colI];
distance = new int[rowI][colI];
for (int i = 0; i < rowI; i++) {
for (int j = 0; j < colI; j++) {
height[i][j] = in.nextInt();
distance[i][j] = 1;
}
}
int totalI = rowI * colI;
for (int i = 0; i < totalI; i++) {
isAltered = false;
for (int j = 0; j < rowI; j++) {
for (int k = 0; k < colI; k++) {
deal(j - 1, k, j, k);
deal(j + 1, k, j, k);
deal(j, k - 1, j, k);
deal(j, k + 1, j, k);
}
}
if (!isAltered) {
break;
}
}
for (int i = 0; i < rowI; i++) {
for (int j = 0; j < colI; j++) {
if (distance[i][j] > ansI) {
ansI = distance[i][j];
}
}
}
System.out.println(ansI);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator