Skip to content

Commit c5fa5cd

Browse files
authored
Merge pull request #141 from zaqquum/main
Hongjoo / 2월 2주차 /3문제
2 parents 0963f0d + 3aa3cba commit c5fa5cd

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

Hongjoo/백준/A2B.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
BOJ#16953. A-> B / Silver 1
3+
https://my-coding-notes.tistory.com/210
4+
"""
5+
from collections import deque
6+
a,b = map(int,input().split())
7+
q = deque()
8+
q.append((a,1))
9+
r = 0
10+
11+
while(q):
12+
n,t = q.popleft()
13+
if n > b:
14+
continue
15+
if n == b:
16+
print(t)
17+
break
18+
q.append((int(str(n)+"1"),t+1))
19+
q.append((n*2,t+1))
20+
else:
21+
print(-1)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
#20057. 마법사 상어와 토네이도
3+
https://www.acmicpc.net/problem/20057
4+
"""
5+
# 허리케인 이동방향
6+
delta = [(0, -1), (1, 0), (0, 1), (-1, 0)]
7+
8+
# 2. 허리케인 방향에 맞춰 비율 배열 바꾸기 -> arr를 반시계방향으로 90도 회전하는 함수
9+
def rotate_90(proportion):
10+
new_proportion = list(reversed(list(zip(*proportion))))
11+
return new_proportion
12+
p = [[0, 0, 0.02, 0, 0], [0, 0.1, 0.07, 0.01, 0], [0.05, 0, 0, 0, 0], [0, 0.1, 0.07, 0.01, 0], [0, 0, 0.02, 0, 0]]
13+
p1 = rotate_90(p)
14+
p2 = rotate_90(p1)
15+
p3 = rotate_90(p2)
16+
proportions = [p, p1, p2, p3]
17+
alphas = [(2, 1), (3, 2), (2, 3), (1, 2)] # 허리케인 이동 방향에 따른 알파 위치
18+
19+
# 3. 허리케인 이동 + 모래 이동
20+
def solution():
21+
# 3-1. 초기 조건 맞추기
22+
outer_sand = 0 # 배열 밖으로 나간 sand
23+
tr = sr # 토네이도 위치 인덱스 -> 시작 지점 부터 시작
24+
tc = sc
25+
curl = 0 # 현재 토네이도 방향
26+
turn = 2 # 토네이도 방향 바꾸는 지표 -> 좌-하 : turn = 2 /우-상: turn = 4, 2씩 늘어난다.
27+
now = 0 # 토네이도 직선 길이
28+
proportion = proportions[0] # 토네이도 방향에 따른 비율 배열
29+
30+
# 3-2 토네이도가 종료될때까지 토네이도 이동 -> 모래 이동 -> 토네이도 방향 바꾸기
31+
while not (tr == 0 and tc == 0): # 토네이도가 종료될 때까지 반복한다.
32+
33+
# 3-2-1. 토네이도 이동
34+
tr += delta[curl][0] # 현재 토네이도 위치
35+
tc += delta[curl][1]
36+
now += 1 # 토네이도 길이 갱신
37+
sand = data[tr][tc]
38+
data[tr][tc] = 0 # 토네이도 위치에 있는 모래는 모두 proportion에 따라 이동한다.
39+
left = sand # proportion으로 이동하고 남은 모래
40+
41+
# 3-2-2. proportion의 y위치와 data의 토네이도 위치를 일치 시켜 모래 정보 갱신하기
42+
for r in range(5):
43+
for c in range(5):
44+
now_sand = int(sand * proportion[r][c])
45+
left -= now_sand
46+
if 0 <= tr + r - 2 < N and 0 <= tc + c - 2 < N: # data 배열 안에 가능하다면 data 갱신
47+
data[tr + r - 2][tc + c - 2] += now_sand
48+
else: # 불가능 하다면 밖으로 나간 모래
49+
outer_sand += now_sand
50+
51+
# alpha 위치에 남은 모래 두기
52+
if 0 <= tr + alphas[curl][0]- 2 < N and 0 <= tc + alphas[curl][1] - 2 < N:
53+
data[tr + alphas[curl][0] - 2][tc + alphas[curl][1] - 2] += left
54+
else:
55+
outer_sand += left
56+
57+
# 3-2-3. 토네이도 방향 바꾸기
58+
if now == turn // 2 or now == turn:
59+
curl = (curl + 1) % 4
60+
proportion = proportions[curl]
61+
if now == turn:
62+
now = 0
63+
turn += 2
64+
65+
# 3-3. 토네이도 종료 후 바깥의 모래
66+
print(outer_sand)
67+
return
68+
69+
70+
# 1. input 받기
71+
N = int(input())
72+
sr = sc = N//2 # 허리케인 시작지점
73+
data = [list(map(int, input().split())) for _ in range(N)]
74+
solution()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
#19638. 센팀와 마법의 뿅망치
3+
https://www.acmicpc.net/problem/19638
4+
# 문제 조건
5+
1. 입력 : 인구수 N , 대조군 키 H , 횟수 제한 T / 거인 키 n1, n2 ...
6+
2. L -> L/2 //
7+
3. T 개 안에 H > N개키
8+
# flow
9+
goal) 키가 큰 거인 선택 -> 때리기
10+
- 최소 길이 1 => H = 1, -> 무조건 No
11+
# 문제 핵심
12+
- sort 사용시 런타임 에러
13+
- 따라서 heapq가 핵심
14+
"""
15+
16+
import sys
17+
import heapq
18+
N , H, threshold= list(map(int, sys.stdin.readline().split()))
19+
20+
heights = []
21+
for i in range(N) :
22+
h = int(sys.stdin.readline())
23+
heapq.heappush(heights ,-1* h)
24+
# heights.append(h)
25+
26+
27+
28+
cnt = 0
29+
for trial in range(threshold+1) :
30+
current_top = -1*heapq.heappop(heights)
31+
if current_top == 1 or H > current_top : # 중간 종료 조건 : (1)
32+
break
33+
34+
if trial >= threshold :
35+
36+
break
37+
38+
heapq.heappush(heights , -1*(current_top// 2))
39+
40+
#1. 가장 큰 거인 VS 센티의 키 차이 비교
41+
42+
if H > current_top :
43+
print("YES")
44+
print(trial)
45+
else :
46+
print("NO")
47+
print(current_top)

0 commit comments

Comments
 (0)