diff --git "a/src/main/kotlin/jimin/47week/A\354\231\200 B 2.py" "b/src/main/kotlin/jimin/47week/A\354\231\200 B 2.py" new file mode 100644 index 00000000..f57eee02 --- /dev/null +++ "b/src/main/kotlin/jimin/47week/A\354\231\200 B 2.py" @@ -0,0 +1,31 @@ +''' +A와 B 문제를 풀고 아이디어를 얻음 +(그냥 완탐시 시간초과) +S -> T 이니까 반대로 T를 S로 만들도록 함 +뒤가 'A'면 그냥 맨 끝을 자르고 +앞이 'B'이면 앞을 하나 자르고 뒤집는다! +''' + +import sys +sys.setrecursionlimit(10**6) +a = list(sys.stdin.readline().rstrip()) +b = list(sys.stdin.readline().rstrip()) +result = 0 + + +def set_recursion(b): + global result, a + if len(a) == len(b): + if a == b: + result = 1 + return + + if b[-1] == 'A': + set_recursion(b[:-1]) + + if b[0] == 'B': + set_recursion(b[:0:-1]) + + +set_recursion(b) +print(result) diff --git "a/src/main/kotlin/jimin/47week/\354\225\214\352\263\240\354\212\244\355\214\237.py" "b/src/main/kotlin/jimin/47week/\354\225\214\352\263\240\354\212\244\355\214\237.py" new file mode 100644 index 00000000..a334bd6b --- /dev/null +++ "b/src/main/kotlin/jimin/47week/\354\225\214\352\263\240\354\212\244\355\214\237.py" @@ -0,0 +1,32 @@ +''' +0-1 너비 우선 탐색 이용! +''' + +import sys +from collections import deque +m, n = map(int, sys.stdin.readline().split()) +miros = [list(map(int, sys.stdin.readline().rstrip())) for _ in range(n)] + +queue = deque([[0, 0, 0]]) +visited = [[0 for _ in range(m)] for _ in range(n)] +visited[0][0] = 1 + +dx = [0, 0, -1, 1] +dy = [-1, 1, 0, 0] +result = -1 +while queue: + nx, ny, num = queue.popleft() + if nx == n - 1 and ny == m - 1: + result = num + break + + for i in range(4): + if 0 <= nx + dx[i] < n and 0 <= ny + dy[i] < m and not visited[nx + dx[i]][ny + dy[i]]: + new = miros[nx + dx[i]][ny + dy[i]] + if new == 0: + queue.appendleft([nx + dx[i], ny + dy[i], num]) + else: + queue.append([nx + dx[i], ny + dy[i], num + 1]) + visited[nx + dx[i]][ny + dy[i]] = 1 + +print(result) diff --git "a/src/main/kotlin/jimin/47week/\354\236\205\352\265\255\354\213\254\354\202\254.py" "b/src/main/kotlin/jimin/47week/\354\236\205\352\265\255\354\213\254\354\202\254.py" new file mode 100644 index 00000000..d3cfffbc --- /dev/null +++ "b/src/main/kotlin/jimin/47week/\354\236\205\352\265\255\354\213\254\354\202\254.py" @@ -0,0 +1,20 @@ +import sys +def solution(n, times): + answer = sys.maxsize + + front = 1 + last = 1_000_000_000 * 1_000_000_000 + + while front <= last: + mid = (front + last) // 2 + num = 0 + for t in times: + num += mid // t + if num < n: + front = mid + 1 + else: + last = mid - 1 + answer = mid + + + return answer \ No newline at end of file diff --git "a/src/main/kotlin/jimin/47week/\355\232\214\354\236\245\353\275\221\352\270\260.py" "b/src/main/kotlin/jimin/47week/\355\232\214\354\236\245\353\275\221\352\270\260.py" new file mode 100644 index 00000000..8001fa71 --- /dev/null +++ "b/src/main/kotlin/jimin/47week/\355\232\214\354\236\245\353\275\221\352\270\260.py" @@ -0,0 +1,41 @@ +''' +bfs를 활용해서 문제를 해결했다 +''' + +import sys +from collections import deque + +n = int(sys.stdin.readline()) +friends = [[] for _ in range(n + 1)] +info = [0 for _ in range(n + 1)] +while True: + a, b = map(int, sys.stdin.readline().split()) + if a == -1 and b == -1: + break + friends[a].append(b) + friends[b].append(a) + +def bfs(target): + global n, info + queue = deque([[target, 0]]) + visited = [0 for _ in range(n + 1)] + + while queue: + now, num = queue.popleft() + for i in friends[now]: + if i != target and not visited[i]: + queue.append([i, num + 1]) + visited[i] = num + 1 + + return num + + +for i in range(1, n + 1): + info[i] = bfs(i) + +mini = min(info[1:]) +print(mini, info.count(mini)) + +for i in range(1, n + 1): + if info[i] == mini: + print(i, end=" ")