Created
March 4, 2020 05:22
-
-
Save dalcon10028/21b78a8d68c2aa84044d85609247b8f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Main { | |
| static int[][] field; | |
| static int white = 0, blue = 0; | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int n = sc.nextInt(); | |
| field = new int[n][n]; | |
| for(int i=0; i<n; i++) | |
| for(int j=0; j<n; j++) | |
| field[i][j] = sc.nextInt(); | |
| coleredPaper(n, 0, 0); | |
| System.out.print(white+"\n"+blue); | |
| } | |
| static void coleredPaper(int n, int x, int y){ | |
| if(isSame(n, x, y)){ | |
| if (field[y][x] == 0) white++; | |
| else blue++; | |
| return; | |
| } | |
| coleredPaper(n/2, x, y); | |
| coleredPaper(n/2, x+n/2, y); | |
| coleredPaper(n/2, x, y+n/2); | |
| coleredPaper(n/2, x+n/2, y+n/2); | |
| } | |
| static boolean isSame(int n, int x, int y){ | |
| int criteria = field[y][x]; | |
| for(int i=y; i<y+n; i++) | |
| for(int j=x; j<x+n; j++) | |
| if (criteria!=field[i][j]) return false; | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment