-
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.
Merge pull request #189 from wellFoundedDevelopers/jimin/47week
[이지민] - A와 B 2, 알고스팟, 회장뽑기, 입국심사
- Loading branch information
Showing
4 changed files
with
124 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,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) |
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,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) |
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,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 |
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,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=" ") |