-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa 10855.cpp
184 lines (112 loc) · 2.87 KB
/
UVa 10855.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <bits/stdc++.h>
#define lp(i,n) for(int i=0; i<n; i++)
using namespace std;
char big[2000][2000];
char small[1000][1000];
char small1[1000][1000];
char small2[1000][1000];
char small3[1000][1000];
char small4[1000][1000];
bool searching1 (int dim_xl,int dim_yl, int dim_xs, int dim_ys, int start_xl, int start_yl)
{
if(dim_xs-1 > dim_xl-1-start_xl) return false;
if(dim_ys-1 > dim_yl-1-start_yl) return false;
for(int i=0; i<dim_xs; i++){
for(int j=0; j<dim_ys; j++){
if(small1[i][j]!=big[start_xl+i][start_yl+j]) return false;
}
}
return true;
}
bool searching2 (int dim_xl,int dim_yl, int dim_xs, int dim_ys, int start_xl, int start_yl)
{
if(dim_xs-1 > dim_xl-1-start_xl) return false;
if(dim_ys-1 > dim_yl-1-start_yl) return false;
for(int i=0; i<dim_xs; i++){
for(int j=0; j<dim_ys; j++){
if(small2[i][j]!=big[start_xl+i][start_yl+j]) return false;
}
}
return true;
}
bool searching3(int dim_xl,int dim_yl, int dim_xs, int dim_ys, int start_xl, int start_yl)
{
if(dim_xs-1 > dim_xl-1-start_xl) return false;
if(dim_ys-1 > dim_yl-1-start_yl) return false;
for(int i=0; i<dim_xs; i++){
for(int j=0; j<dim_ys; j++){
if(small3[i][j]!=big[start_xl+i][start_yl+j]) return false;
}
}
return true;
}
bool searching4 (int dim_xl,int dim_yl, int dim_xs, int dim_ys, int start_xl, int start_yl)
{
if(dim_xs-1 > dim_xl-1-start_xl) return false;
if(dim_ys-1 > dim_yl-1-start_yl) return false;
for(int i=0; i<dim_xs; i++){
for(int j=0; j<dim_ys; j++){
if(small4[i][j]!=big[start_xl+i][start_yl+j]) return false;
}
}
return true;
}
int main()
{
while(true){
int N,n;
cin>>N>>n;
if(N==0 && n==0) return 0;
int a=0,b=0,c=0,d=0;
lp(i,N){
cin>>big[i];
}
lp(i,n){
cin>>small1[i];
}
lp(i,n){
lp(j,n){
small2[j][n-1-i]=small1[i][j];
}
}
lp(i,n){
lp(j,n){
small3[j][n-1-i]=small2[i][j];
}
}
lp(i,n){
lp(j,n){
small4[j][n-1-i]=small3[i][j];
}
}
lp(i,N){
lp(j,N){
if(searching1(N,N,n,n,i,j)){
a++;
}
}
}
lp(i,N){
lp(j,N){
if(searching2(N,N,n,n,i,j)){
b++;
}
}
}
lp(i,N){
lp(j,N){
if(searching3(N,N,n,n,i,j)){
c++;
}
}
}
lp(i,N){
lp(j,N){
if(searching4(N,N,n,n,i,j)){
d++;
}
}
}
cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}
}