Skip to content

Commit cc8814e

Browse files
authored
Merge pull request #641 from baekhangyeol/main
[백한결] 95차 라이브 코테 제출
2 parents 8ba8921 + f63b6de commit cc8814e

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

live9/test95/문제1/백한결.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import itertools
2+
3+
4+
def solution(k, dungeons):
5+
answer = -1
6+
7+
counts = []
8+
9+
p = itertools.permutations(dungeons, len(dungeons))
10+
11+
for i in p:
12+
counts.append(maxDungeons(k, i))
13+
14+
counts.sort()
15+
16+
return counts[-1]
17+
18+
19+
def maxDungeons(k, dungeons):
20+
count = 0
21+
health = k
22+
23+
for dungeon in dungeons:
24+
if dungeon[0] > health:
25+
break
26+
else:
27+
count += 1
28+
health -= dungeon[1]
29+
30+
return count

live9/test95/문제2/백한결.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def solution(n, wires):
2+
3+
min_difference = float('inf')
4+
5+
for i in range(len(wires)):
6+
graph = {j: [] for j in range(1, n+1)}
7+
8+
for j, (v1, v2) in enumerate(wires):
9+
if i != j:
10+
graph[v1].append(v2)
11+
graph[v2].append(v1)
12+
13+
visited = [False] * (n+1)
14+
count = dfs(1, graph, visited)
15+
16+
min_difference = min(min_difference, abs(count-(n-count)))
17+
18+
return min_difference
19+
20+
21+
def dfs(start, graph, visited):
22+
visited[start] = True
23+
count = 1
24+
25+
for neighbor in graph[start]:
26+
if not visited[neighbor]:
27+
count += dfs(neighbor, graph, visited)
28+
29+
return count
30+
31+
print(solution(9, [[1,3],[2,3],[3,4],[4,5],[4,6],[4,7],[7,8],[7,9]]))

live9/test95/문제3/백한결.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import itertools
2+
3+
4+
def solution(brown, yellow):
5+
answer = []
6+
pair = []
7+
8+
total = brown + yellow
9+
10+
divisors = getDivisor(total)
11+
12+
for comb in itertools.product(divisors, repeat=2):
13+
if (comb[0] - 2) * (comb[1] - 2) == yellow and comb[0] >= comb[1]:
14+
pair.append(comb)
15+
16+
pair.sort(reverse=True)
17+
18+
answer.append(pair[0][0])
19+
answer.append(pair[0][1])
20+
21+
return answer
22+
23+
24+
def getDivisor(num):
25+
divisors = []
26+
27+
for i in range(1, num + 1):
28+
if num % i == 0:
29+
divisors.append(i)
30+
31+
return divisors

0 commit comments

Comments
 (0)