-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path031401.cpp
More file actions
78 lines (64 loc) · 2.16 KB
/
Copy path031401.cpp
File metadata and controls
78 lines (64 loc) · 2.16 KB
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
#include <string>
#include <vector>
using namespace std;
bool solution(vector<vector<int>> key, vector<vector<int>> lock) {
bool answer = false;
int kx = key.size();
int ky = key[0].size();
int lx = lock.size();
int ly = lock[0].size();
int tmp[20][20];
int check[20][20];
for(int t=0; t<4 && !answer; t++){
for(int x = -kx+1; x < lx && !answer; x++){
for(int y = -ky+1; y < ly && !answer; y++){
bool flag = true;
for(int i=0; i<lx; i++){
for(int j=0; j<ly; j++){
check[i][j] = lock[i][j];
}
}
for(int m = 0; m<kx && flag; m++){
for(int n=0; n<ky && flag; n++){
int a = x+m;
int b = y+n;
if(a>=0 && b>=0 && a < lx && b < ly){
if(key[m][n]==0 && lock[a][b] == 0){
flag = false;
}
else if(key[m][n]==1 && lock[a][b] == 1){
flag = false;
}
else if(key[m][n]==1){
check[a][b] = 1;
}
}
}
}
if(flag){
bool flag2 = true;
for(int i=0; i<lx && flag2; i++){
for(int j=0; j<ly && flag2; j++){
if(check[i][j] == 0){
flag2=false;
}
}
}
if(flag2) answer=true;
}
}
}
for(int i=0; i<kx; i++){
for(int j=0; j<ky; j++){
tmp[ky-j-1][i] = key[i][j];
}
}
for(int i=0; i<ky; i++){
for(int j=0; j<kx; j++){
key[i][j] = tmp[i][j];
}
}
swap(kx, ky);
}
return answer;
}