-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1034162_UVA201_20170227.c
65 lines (64 loc) · 1.38 KB
/
A1034162_UVA201_20170227.c
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
#include<stdio.h>
int graph[20][20][2],square[20],mark[20][20];
int pp[4][2]={0,0,0,0,-1,0,0,-1},d[4]={1,0,1,0},m[4][2]={1,0,0,1,-1,0,0,-1};
void finds(int gl,int ll,int c,int x,int y){
if(gl==ll){
if(c==3){
square[gl]++;
return;
}
c++;ll=0;
if(graph[x+pp[c][0]][y+pp[c][1]][d[c]]==1)
finds(gl,ll+1,c,x+m[c][0],y+m[c][1]);
return;
}
if(graph[x+pp[c][0]][y+pp[c][1]][d[c]]==1)
finds(gl,ll+1,c,x+m[c][0],y+m[c][1]);
}
main(){
int i,j,l,n,k,x,y;
int p=1;
char d[10];
while(scanf("%d\n",&n)!=EOF){
scanf("%d\n",&k);
for(i=0;i<=20;i++){
square[i]=0;
for(j=0;j<=20;j++){
graph[i][j][0]=0;
graph[i][j][1]=0;
mark[i][j]=0;
}
}
for(i=0;i<k;i++){
gets(d);
x=d[2]-'0';y=d[4]-'0';
if(d[0]=='H')
graph[x][y][0]=1;
if(d[0]=='V')
graph[y][x][1]=1;
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
for(l=1;l<=n;l++){
if(mark[i][j]>=l)continue;
mark[i][j]=l;
finds(l,0,0,i,j);
}
}
}
if(p>1)
printf("\n**********************************\n\n");
printf("Problem #%d\n\n",p++);
for(i=1;i<=n&&square[i]==0;i++);
if(n==1){
printf("%d square (s) of size %d\n",1,1);
continue;
}
if(i==n+1)
printf("No completed squares can be found.\n");
for(i=1;i<=n;i++){
if(square[i]>0)
printf("%d square (s) of size %d\n",square[i],i);
}
}
}