标签:tco ret port lan == while builder util 解决
暴力直接解决, 输入处理较为麻烦。
LeetCode 85 一样。
import java.util.*;
public class Main {
static int solve(int[][] arr, int n, int m) {
int area = 0;
for(int a = 0; a < n; a++){
for(int b = 0; b < m; b++) {
for(int c = 0; c <= a; c++){
for(int d = 0; d <= b; d++) {
int t = 0;
for(int i=c; i <= a; i++)
for(int j=d; j <= b; j++)
if(arr[i][j] == 1) t++;
if(t == (a-c+1)*(b-d+1))
area = Math.max(area, t);
}
}
}
}
return area;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
if(sc.hasNext()) sc.nextLine();
List<String> list = new ArrayList<>();
while(true){
char[] s = sc.nextLine().toCharArray();
StringBuilder sb = new StringBuilder();
for(int i=0; i < s.length;i++)
if(s[i] == ‘0‘ || s[i] == ‘1‘)
sb.append(s[i]);
if(sb.length() == 0) break;
list.add(sb.toString());
if(s[s.length-1] != ‘,‘) break;
}
if(sc.hasNext()) sc.nextLine();
int n = list.size(), m = list.get(0).length();
int[][] a = new int[n][m];
for(int i=0; i < n; i++)
for(int j=0; j < m; j++)
a[i][j] = list.get(i).charAt(j) == ‘1‘ ? 1 : 0;
int area = solve(a, n, m);
System.out.println(area);
}
}
标签:tco ret port lan == while builder util 解决
原文地址:https://www.cnblogs.com/lixyuan/p/13288574.html