Skip to content

Commit 7a4fd68

Browse files
authored
찬민 백준 숙제 (#82)
1 parent 7127d03 commit 7a4fd68

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

‎cmkim/BaekJoon/백준_17179.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
n, m, l = map(int, input().split())
2+
3+
cut = []
4+
arr = []
5+
for i in range(m): # 자르는 위치
6+
cut.append(int(input()))
7+
#print(cut)
8+
9+
for i in range(n): # 자르는 횟수
10+
arr.append(int(input()))
11+
12+
def calculate(mid, count): # 가장 작은 조각의 길이 > mid 일때 횟수��� 세서 count 값이 만들어지면 성공
13+
prev = 0
14+
for i in range(m):
15+
if cut[i] - prev >= mid:
16+
count -= 1
17+
prev = cut[i]
18+
if count == 0:
19+
break
20+
21+
22+
if count == 0 and l - prev >= mid:
23+
return True
24+
else:
25+
return False
26+
27+
for i in range(n):
28+
piece = arr[i]
29+
left = 0
30+
right = l
31+
32+
while left + 1 < right:
33+
mid = (left + right) // 2
34+
if calculate(mid, piece):
35+
left = mid
36+
else:
37+
right = mid
38+
39+
print(left)
40+
41+
42+
43+
44+
45+

‎cmkim/BaekJoon/백준_4386.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import sys, math, heapq
2+
n = int(input())
3+
4+
arr = []
5+
connected = []
6+
sum = 0
7+
cost = 1e9
8+
9+
def dist(x1, y1, x2, y2):
10+
return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
11+
12+
for i in range(n):
13+
x, y = map(float, input().split())
14+
arr.append((x, y))
15+
16+
q = []
17+
connected.append(0)
18+
for i in range(1, n):
19+
heapq.heappush(q, (dist(arr[0][0], arr[0][1], arr[i][0], arr[i][1]), i))
20+
21+
# print(connected)
22+
# print(q)
23+
24+
while n != len(connected):
25+
value, node = heapq.heappop(q)
26+
while node in connected:
27+
value, node = heapq.heappop(q)
28+
29+
sum += value
30+
connected.append(node)
31+
32+
for i in range(n):
33+
if i not in connected:
34+
heapq.heappush(q, (dist(arr[node][0], arr[node][1], arr[i][0], arr[i][1]), i))
35+
36+
print("%.2f"%(sum))
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+

‎cmkim/이것이 취업을 위한 코딩 테스트다/특정 거리의 도시 찾기_339p.py

Whitespace-only changes.

0 commit comments

Comments
 (0)