-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1780.cpp
70 lines (57 loc) · 1.07 KB
/
1780.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>
void cutPaper(long long x, long long y, long long size);
int num[3]={0,};
int** paper;
int main(){
long long n;
long long i,j;
scanf("%lld",&n);
paper=(int**)malloc(sizeof(int*)*n);
for(i=0;i<n;i++){
paper[i]=(int*)malloc(sizeof(int)*n);
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&paper[i][j]);
}
}
cutPaper(0,0,n);
printf("%d\n%d\n%d",num[0],num[1],num[2]);
}
void cutPaper(long long x, long long y, long long size){
long long i,j;
int base=paper[x][y];
int flag=0;
long long quad=size/3;
if(size<2){
num[base+1]++;
return;
}
for(i=x;i<x+size;i++){
for(j=y;j<y+size;j++){
if(paper[i][j]!=base){
flag=1;
break;
}
}
if(flag==1){
break;
}
}
if(flag!=1){
num[base+1]++;
return;
}
else{
cutPaper(x,y,quad);
cutPaper(x,y+quad,quad);
cutPaper(x,y+2*quad, quad);
cutPaper(x+quad,y,quad);
cutPaper(x+quad,y+quad,quad);
cutPaper(x+quad,y+2*quad, quad);
cutPaper(x+2*quad,y,quad);
cutPaper(x+2*quad,y+quad,quad);
cutPaper(x+2*quad,y+2*quad, quad);
}
}