-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34e43f0
commit 7ffe09f
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 자물쇠와 열쇠 | ||
|
||
def transpose_key(key): | ||
new_key = [] | ||
for k in zip(*key): | ||
new_key.append(k) | ||
new_key.reverse() | ||
return new_key | ||
|
||
|
||
def check_lock(big_lock, lock_len): | ||
for x in range(lock_len, 2 * lock_len): | ||
for y in range(lock_len, 2 * lock_len): | ||
if big_lock[x][y] != 1: | ||
return False | ||
return True | ||
|
||
|
||
def solution(key, lock): | ||
key_len = len(key) | ||
lock_len = len(lock) | ||
|
||
big_lock = [[0] * lock_len * 3 for i in range(lock_len * 3)] | ||
|
||
for i in range(lock_len, 2 * lock_len): | ||
for j in range(lock_len, 2 * lock_len): | ||
big_lock[i][j] = lock[i - lock_len][j - lock_len] | ||
|
||
# print(*big_lock,sep='\n') | ||
|
||
for _ in range(4): | ||
key = transpose_key(key) | ||
|
||
# print(*key, sep='\n') | ||
# print() | ||
|
||
for i in range(2 * lock_len): | ||
for j in range(2 * lock_len): | ||
for x in range(key_len): | ||
for y in range(key_len): | ||
big_lock[i + x][j + y] += key[x][y] | ||
|
||
if check_lock(big_lock, lock_len): | ||
return True | ||
|
||
for x in range(key_len): | ||
for y in range(key_len): | ||
big_lock[i + x][j + y] -= key[x][y] | ||
# print(*big_lock,sep='\n') | ||
return False |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
n = int(input()) | ||
A = list(map(int, input().split())) | ||
m = int(input()) | ||
B = list(map(int, input().split())) | ||
|
||
A.sort() | ||
|
||
answer = [] | ||
|
||
for i in B: | ||
start = 0 | ||
end = len(A) | ||
check = False | ||
while start <= end: | ||
mid = (start + end) // 2 | ||
|
||
if A[mid] == i: | ||
check = True | ||
break | ||
elif i < A[mid]: | ||
end = mid - 1 | ||
elif A[mid] < i: | ||
start = mid + 1 | ||
|
||
if check: | ||
answer.append('yes') | ||
else: | ||
answer.append('no') | ||
|
||
print(*answer, sep=' ') |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from itertools import combinations | ||
|
||
def dfs(array, x, y, d): | ||
global n | ||
# teacher가 탐색한다. | ||
# 탐색해서 학생을 찾으면 true | ||
dx = x + d[0] | ||
dy = y + d[1] | ||
|
||
if 0 <= dx < n and 0 <= dy < n: | ||
if array[dx][dy] == 'X': | ||
answer = dfs(array, dx, dy, d) | ||
elif array[dx][dy] == 'S': | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False | ||
|
||
return answer | ||
|
||
global array, student, teacher, no_exist, n | ||
|
||
n = int(input()) | ||
|
||
array = [] | ||
student = [] | ||
teacher = [] | ||
no_exist = [] | ||
|
||
for i in range(n): | ||
temp = list(input().split()) | ||
array.append(temp) | ||
for j in range(n): | ||
if temp[j] == 'S': | ||
student.append((i, j)) | ||
elif temp[j] == 'T': | ||
teacher.append((i, j)) | ||
elif temp[j] == 'X': | ||
no_exist.append((i, j)) | ||
|
||
def solution(): | ||
global array, student, teacher, no_exist, n | ||
|
||
combi_no_exists = list(combinations(no_exist, 3)) | ||
ds = ((0, -1), (1, 0), (0, 1), (-1, 0)) | ||
|
||
for combi_no_exist in combi_no_exists: | ||
temp_array = [i[:] for i in array] | ||
answer = [] | ||
for i in combi_no_exist: | ||
x, y = i | ||
temp_array[x][y] = 'O' | ||
|
||
for t in teacher: | ||
x, y = t | ||
search_d = [] | ||
for d in ds: | ||
search_d.append(dfs(temp_array, x, y, d)) | ||
if True in search_d: | ||
answer.append(True) | ||
break | ||
if True in answer: | ||
continue | ||
# 모든 학생이 감시로부터 피했다면 | ||
return "YES" | ||
return "NO" | ||
|
||
print(solution()) |