Untitled
unknown
plain_text
2 years ago
1.2 kB
11
Indexable
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class CuttingaPiece {
static int t, demTrang, demXanh;
static final int MAX = 1005;
static int[][] A = new int[MAX][MAX];
static boolean res;
static int kt;
public static void dequy(int n, int x, int y){
res = true;
kt = A[x][y];
for(int i = x; i < x+n; i++){
for(int j = y; j < y + n; j++){
if(kt != A[i][j]){
res = false;
break;
}
}
}
if(res){
if(kt == 1){
demXanh++;
}else{
demTrang++;
}
}else{
dequy(n/2, x, y);
dequy(n/2, x, y + n / 2);
dequy(n/2, x + n / 2, y);
dequy(n/2, x + n / 2, y + n / 2);
}
}
public static void main(String[] args) throws FileNotFoundException {
System.setIn(new FileInputStream("Text"));
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
for (int Case = 1; Case <= tc; Case++){
System.out.println("Case #" + Case);
t = sc.nextInt();
demTrang = 0;
demXanh = 0;
for(int i = 0; i < t; i++){
for(int j = 0; j < t; j++){
A[i][j] = sc.nextInt();
}
}
dequy(t, 0, 0);
System.out.println(demTrang + " " + demXanh);
}
}
}
Editor is loading...