Skip to content

Commit 7c10764

Browse files
authored
[기재현] 1주차
[기재현] 1주차
2 parents 72552f3 + e6cdd70 commit 7c10764

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

1주차_기재현/1로만들기.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
n = int(input())
2+
3+
# dp = 1로 만들기 위한 최소 연산 횟수
4+
# 가능한 연산은 3가지
5+
# 1. dp[i] = dp[i-1] + 1
6+
# 2. dp[i//2] + 1
7+
# 3. dp[i//3] + 1
8+
# 근데 나눠지는지 미리 체크해줘야됨
9+
10+
dp = [0] * (n + 1)
11+
for i in range(2, n + 1):
12+
dp[i] = dp[i - 1] + 1
13+
if i % 2 == 0:
14+
dp[i] = min(dp[i], dp[i // 2] + 1)
15+
if i % 3 == 0:
16+
dp[i] = min(dp[i], dp[i // 3] + 1)
17+
18+
print(dp[n])

1주차_기재현/달팽이.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
n = int(input())
2+
target = int(input())
3+
4+
# 상 우 하 좌
5+
dx = [-1, 0, 1, 0]
6+
dy = [0, 1, 0, -1]
7+
ii = 0
8+
9+
arr = [[0 for _ in range(n)] for _ in range(n)]
10+
i, j = n // 2, n // 2
11+
12+
cur_num = 1
13+
arr[i][j] = cur_num
14+
count, turn, flag = 1, 1, 0
15+
ans = []
16+
while cur_num <= n ** 2:
17+
if cur_num == target:
18+
ans = [i + 1,j + 1]
19+
20+
arr[i][j] = cur_num
21+
i, j = i + dx[ii], j + dy[ii]
22+
23+
if count == turn:
24+
if flag == 1:
25+
turn += 1
26+
flag = 0
27+
else:
28+
flag = 1
29+
count = 0
30+
ii = (ii + 1) % 4
31+
32+
count += 1
33+
cur_num += 1
34+
35+
for i in range(n):
36+
print(' '.join(map(str, arr[i])))
37+
38+
print(ans[0], ans[1])

1주차_기재현/두 스티커.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from itertools import combinations
2+
3+
H, W = map(int, input().split())
4+
N = int(input())
5+
stickers = [tuple(map(int, input().split())) for _ in range(N)]
6+
7+
max_size = 0
8+
9+
for comb in combinations(stickers, 2):
10+
sticker1, sticker2 = comb
11+
# 스티커1 회전: (h1, w1), (w1, h1)
12+
s1_variants = [sticker1, (sticker1[1], sticker1[0])]
13+
# 스티커2 회전: (h2, w2), (w2, h2)
14+
s2_variants = [sticker2, (sticker2[1], sticker2[0])]
15+
16+
for s1 in s1_variants:
17+
for s2 in s2_variants:
18+
h1, w1 = s1
19+
h2, w2 = s2
20+
# 수평 배치
21+
if max(h1, h2) <= H and w1 + w2 <= W:
22+
max_size = max(max_size, h1 * w1 + h2 * w2)
23+
# 수직 배치
24+
if max(w1, w2) <= W and h1 + h2 <= H:
25+
max_size = max(max_size, h1 * w1 + h2 * w2)
26+
27+
print(max_size)

1주차_기재현/바이러스.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from collections import deque, defaultdict
2+
3+
N = int(input())
4+
M = int(input())
5+
edges = [tuple(map(int, input().split())) for _ in range(M)]
6+
7+
neighbors = defaultdict(list)
8+
for edge in edges:
9+
a, b = edge
10+
neighbors[a].append(b)
11+
neighbors[b].append(a)
12+
13+
14+
# bfs
15+
queue = deque([1])
16+
visited = set()
17+
visited.add(1)
18+
count = 0
19+
20+
while queue:
21+
node = queue.popleft()
22+
for neighbor in neighbors[node]:
23+
if neighbor not in visited and neighbor not in queue:
24+
queue.append(neighbor)
25+
visited.add(neighbor)
26+
count += 1
27+
28+
print(count)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
N = int(input())
2+
nums = list(map(int, input().split()))
3+
4+
nums.sort()
5+
ans = 0
6+
7+
# 홀수일때는 미리 하나 뺌
8+
if N % 2 == 1:
9+
ans = nums[-1]
10+
nums = nums[:-1]
11+
N -= 1
12+
13+
# 근손실의 최적의 경우의 수의 최댓값
14+
for i in range(N // 2):
15+
ans = max(ans, nums[i] + nums[N - 1 - i])
16+
17+
print(ans)

0 commit comments

Comments
 (0)