Untitled
unknown
plain_text
2 years ago
1.3 kB
8
Indexable
package Cutting_a_Piece_of_Colored_Paper;
import java.io.FileInputStream;
import java.util.Scanner;
class Solution{
static int[][] a;
static int n;
static int white, blu;
public static int check(int hang, int cot, int l ){
int sum = 0;
for(int i = hang; i < hang+l; i++){
for(int j = cot; j < cot+l; j++){
sum += a[i][j];
}
}
if(sum == 0) return 0;
if(sum == l*l) return 1;
return -1;
}
public static void count(int hang, int cot, int l){
int x = check(hang, cot, l);
if(x == 0){
white ++;
}else if(x == 1){
blu++;
}else{
count(hang, cot, l/2);
count(hang + l/2, cot, l/2);
count(hang, cot + l/2, l/2);
count(hang + l/2, cot + l/2, l/2);
}
}
public static void main(String args[]) throws Exception{
// System.setIn(new FileInputStream("input.txt"));
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++){
white = 0;
blu = 0;
n = sc.nextInt();
a = new int[n][n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
a[i][j] = sc.nextInt();
}
}
count(0, 0, n);
System.out.println("Case #" + test_case + "\n" + white + " " + blu);
}
sc.close();
}
}
Editor is loading...