Skip to content

Commit 0277738

Browse files
authored
Merge pull request #222 from AlgorithmStudy-Allumbus/minjeong3
Minjeong / 6월 2주차 / 3문제
2 parents 65f8d4a + 69dd1d0 commit 0277738

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
from collections import deque
3+
4+
input = sys.stdin.readline
5+
6+
MAX = 100000
7+
N, K = map(int, input().split())
8+
dist = [-1] * (MAX + 1)
9+
ways = [0] * (MAX + 1)
10+
11+
queue = deque([N])
12+
dist[N] = 0
13+
ways[N] = 1
14+
15+
while queue:
16+
x = queue.popleft()
17+
18+
for nx in (x - 1, x + 1, x * 2):
19+
# 범위 내
20+
if 0 <= nx <= MAX:
21+
# 아직 방문하지 않은 위치
22+
if dist[nx] == -1:
23+
dist[nx] = dist[x] + 1 # 현재 걸린 시간 +1 초
24+
ways[nx] = ways[x] # 이전 위치에서 오는 방법의 수 가져오기
25+
queue.append(nx)
26+
# 이미 방문했지만, 같은 시간에 다시 도달한 경우
27+
elif dist[nx] == dist[x] + 1:
28+
ways[nx] += ways[x] # 기존 방법 수 + 새로운 경로 수
29+
30+
print(dist[K])
31+
print(ways[K])
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
MAX = 100000
6+
N, K = map(int, input().split())
7+
8+
visited = [0] * (MAX+1)
9+
queue = deque([N])
10+
11+
while queue:
12+
current = queue.popleft()
13+
if current == K:
14+
break
15+
for nx in (current + 1, current - 1, current * 2):
16+
if 0 <= nx <= MAX and not visited[nx]:
17+
visited[nx] = visited[current] + 1
18+
queue.append(nx)
19+
20+
print(visited[K])
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sys
2+
import math
3+
input = sys.stdin.readline
4+
5+
money = int(input())
6+
prices = list(map(int, input().split()))
7+
8+
# 준현이 (BNP)
9+
jh_cash = money
10+
jh_stock = 0
11+
for price in prices:
12+
if jh_cash >= price:
13+
jh_stock += jh_cash // price
14+
jh_cash = jh_cash % price
15+
jh_total = jh_cash + jh_stock * prices[-1]
16+
17+
# 성민이 (TIMING)
18+
sm_cash = money
19+
sm_stock = 0
20+
for i in range(3, 14):
21+
# 3일 연속 상승
22+
if prices[i-3] < prices[i-2] < prices[i-1]:
23+
sm_cash += sm_stock * prices[i]
24+
sm_stock = 0
25+
# 3일 연속 하락
26+
elif prices[i-3] > prices[i-2] > prices[i-1]:
27+
can_buy = sm_cash // prices[i]
28+
sm_stock += can_buy
29+
sm_cash -= can_buy * prices[i]
30+
sm_total = sm_cash + sm_stock * prices[-1]
31+
32+
# 결과 출력
33+
if jh_total > sm_total:
34+
print("BNP")
35+
elif jh_total < sm_total:
36+
print("TIMING")
37+
else:
38+
print("SAMESAME")

0 commit comments

Comments
 (0)