Skip to content

Commit

Permalink
Merge pull request #189 from wellFoundedDevelopers/jimin/47week
Browse files Browse the repository at this point in the history
[이지민] - A와 B 2, 알고스팟, 회장뽑기, 입국심사
  • Loading branch information
jeeminimini authored Oct 8, 2023
2 parents 036921a + 9076678 commit 2c85f2a
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/kotlin/jimin/47week/A와 B 2.py
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)
32 changes: 32 additions & 0 deletions src/main/kotlin/jimin/47week/알고스팟.py
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)
20 changes: 20 additions & 0 deletions src/main/kotlin/jimin/47week/입국심사.py
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
41 changes: 41 additions & 0 deletions src/main/kotlin/jimin/47week/회장뽑기.py
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=" ")

0 comments on commit 2c85f2a

Please sign in to comment.