| ||||||||||
| 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 | |||||||||
帮我看看为什么老是RTE吧!(算法应该没有错,就是效率应该不是很高)谢谢啦!In Reply To:1050不是很简单,先做简单题吧 Posted by:hawk at 2005-07-27 11:42:47 import java.io.*;
import java.util.*;
import java.lang.Math;
public class Main {
public static void main(String[] args) throws Exception{
int[][] arrayInput= new int[100][];
int max = -127;
// Input
BufferedReader stdinN =
new BufferedReader(
new InputStreamReader(System.in));
String lineN = stdinN.readLine();
StringTokenizer stN = new StringTokenizer(lineN);
int n = Integer.parseInt(stN.nextToken());
if (n>100 || n==0) {
System.out.println("ERROR! 0<n<=100");
return;
}
BufferedReader stdinArr =
new BufferedReader(
new InputStreamReader(System.in));
String lineArr = stdinArr.readLine();
StringTokenizer stArr = new StringTokenizer(lineArr);
for (int i=0; i<n; i++) {
arrayInput[i] = new int[n];
for(int j=0; j<n; j++) {
arrayInput[i][j] = Integer.parseInt(stArr.nextToken());
if (arrayInput[i][j] <-127 || arrayInput[i][j] >127) {
System.out.println("ERROR! -127<Number<127");
return;
}
}
}
ArrayFun arr = new ArrayFun(arrayInput, n);
for(int i=0; i<n; i++) {
max = Math.max(arr.FindMax(i), max);
}
System.out.println(max);
}
}
class ArrayFun {
private int[][] rectangle;
private int iN;
private int[] colSum = new int[100];
public ArrayFun(int[][] Rectangle, int in) {
this.rectangle = Rectangle;
iN = in;
}
public int FindMax(int row) {
int iMax = -127;
int j=0;
int iSum = 0;
// initialize the array colSum
for(j=0; j<iN; j++) {
colSum[j] = 0;
}
for(int i=row; i<iN; i++) {
for(j=0; j<iN; j++) {
colSum[j] += rectangle[i][j];
iMax = Math.max(colSum[j], iMax);
iSum = colSum[j];
int k = j-1;
if (j>0) {
while (k>=0) {
iSum += colSum[k];
iMax = Math.max(iSum, iMax);
k--;
}
}
}
}//for
return iMax;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator