keep 第三题,考完试了,才调试出来~~ 求用IDE~
TMD不让用IDE,一直20%
考完试了,debug 2分钟,基本能通过各种例子~~~
大佬们看看
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col = sc.nextInt();
int[][] status = new int[row][col];
int[][] nums = new int[row][2];
for (int i = 0; i < row; i++) {
int begin = -1, end = -1;
boolean flag = false;
for (int j = 0; j < col; j++) {
status[i][j] = sc.nextInt();
if (begin == -1 && status[i][j] == 1) {
begin = j;
end = begin;
}
if (begin != -1 && status[i][j] == 0) {
flag = true;
}
if (begin != -1 && status[i][j] == 1 && !flag) {
end++;
}
}
nums[i][0] = begin;
nums[i][1] = end-1;
}
System.out.println(getMaxArea(nums));
}
public static int getMaxArea(int[][] nums) {
int rows = nums.length;
int result = 0;
boolean flag = false;
int l = Integer.MAX_VALUE, r = Integer.MAX_VALUE;
for (int i = 0; i < rows - 1; i++) {
if (nums[i][0] != -1) {
if (flag == true) {
l = Integer.MAX_VALUE;
r = Integer.MAX_VALUE;
flag = false;
}
if (nums[i][0] >= nums[i + 1][0] && nums[i][0] <= nums[i + 1][1]) {
if (l == Integer.MAX_VALUE && r == Integer.MAX_VALUE) {
l = Math.min(nums[i][1], nums[i + 1][1]) - Math.max(nums[i][0], nums[i + 1][0]) + 1;
r = 2;
} else if (!flag) {
int temp = Math.min(nums[i][1], nums[i + 1][1]) - Math.max(nums[i][0], nums[i + 1][0]) + 1;
l = Math.min(l, temp);
r++;
}
if (l != Integer.MAX_VALUE) {
result = Math.max(result, r * l);
}
} else {
flag = true;
}
}
}
return result;
}
}
#Keep#