Skip to content

Commit dfc08c8

Browse files
committed
Merge branch 'main' into kcm_09_06
2 parents b02fc28 + 5526c25 commit dfc08c8

File tree

219 files changed

+3480
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+3480
-28
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def solution(lottery):
2+
answer = -1
3+
4+
arr = [0] * 1001
5+
visited = [0] * 1001
6+
sum = 0
7+
count = 0
8+
for i in range(len(lottery)):
9+
if lottery[i][1] == 0 and visited[lottery[i][0]] == 0:
10+
arr[lottery[i][0]] += 1
11+
else:
12+
visited[lottery[i][0]] = 1
13+
14+
for i in range(1000):
15+
if visited[i]:
16+
sum += arr[i]
17+
count += 1
18+
#print(sum, count)
19+
20+
if sum:
21+
answer = (sum+count) // count
22+
else:
23+
answer = 0
24+
25+
return answer
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from _collections import deque
2+
3+
4+
5+
dx = [-1, 1, 0, 0] #상하좌우
6+
dy = [0, 0, -1, 1]
7+
8+
def solution(grid):
9+
answer = 0
10+
row = len(grid)
11+
col = len(grid[0])
12+
map = [[1e9] * col for _ in range(row)]
13+
map[0][0] = grid[0][0]
14+
q = deque()
15+
q.append((0, 0))
16+
17+
while q:
18+
x, y = q.popleft()
19+
for i in range(4):
20+
nx = x + dx[i]
21+
ny = y + dy[i]
22+
if 0 <= nx < row and 0 <= ny < col:
23+
if map[x][y] + grid[nx][ny] < map[nx][ny]:
24+
map[nx][ny] = map[x][y] + grid[nx][ny]
25+
q.append((nx, ny))
26+
27+
28+
answer = map[row-1][col-1]
29+
30+
31+
return answer

cmkim/BaekJoon/백준_17179.py

Lines changed: 45 additions & 0 deletions
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/백준_1939.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 처음엔 플로이드워셜 알고리즘을 사용하는 줄 알았는데
2+
# 플로이드 워셜은 최솟값 구할때만 해당하는듯
3+
# 이 문제는 이때동안 풀었던 유형이랑 좀 다른게
4+
# 노드를 탐색해 나가며 최대 중량을 찾아 나가는게 아니라
5+
# 최대 중량을 설정하고 이게 되는지 안되는지 판단해야됌
6+
# 원래가 바텀업방식이라면 이건 탑다운 방식? 이 개념이 맞는지는 잘 모르겠다.
7+
import sys
8+
from _collections import deque
9+
n, m = map(int, input().split())
10+
11+
def bfs(mid):
12+
13+
q = deque()
14+
q.append(start_point)
15+
visited[start_point] = 1
16+
17+
while q:
18+
start = q.popleft()
19+
if start == end_point:
20+
return True
21+
for n_node, n_cost in arr[start]:
22+
if visited[n_node] == 0 and mid <= n_cost:
23+
q.append(n_node)
24+
visited[n_node] = 1
25+
return False
26+
27+
28+
arr = [[] for _ in range(n+1)]
29+
30+
for i in range(m):
31+
a, b, c = map(int, input().split())
32+
arr[a].append((b, c))
33+
arr[b].append((a, c))
34+
35+
start_point, end_point = map(int, input().split())
36+
37+
38+
left, right = 1, 1e9
39+
result = 0
40+
41+
while left <= right:
42+
visited = [0 for _ in range(n + 1)]
43+
mid = (left + right) // 2
44+
if bfs(mid): #중량이 통과했을때
45+
left = mid + 1
46+
result = mid
47+
else: #중량 통과 못했을때
48+
right = mid - 1
49+
50+
print(int(result))

cmkim/BaekJoon/백준_2469.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
k = int(input())
3+
n = int(input())
4+
5+
6+
7+
start = list(map(chr, range(65, 65+k)))
8+
mid = []
9+
end = []
10+
end = list(map(str, input().strip()))
11+
12+
arr = []
13+
14+
for i in range(n):
15+
temp = list(map(str, input().strip()))
16+
if temp[0] == '?':
17+
q_mark = i
18+
arr.append(temp)
19+
20+
21+
# for i in range(n):
22+
# print(arr[i])
23+
24+
for i in range(0, q_mark):
25+
for j in range(k-1):
26+
if arr[i][j] == '-':
27+
tempc = start[j]
28+
start[j] = start[j+1]
29+
start[j+1] = tempc
30+
31+
for i in range(n-1, q_mark, -1):
32+
for j in range(k-1):
33+
if arr[i][j] == '-':
34+
tempc = end[j]
35+
end[j] = end[j+1]
36+
end[j+1] = tempc
37+
38+
# print(start)
39+
# print(end)
40+
41+
for i in range(k-1):
42+
if start[i] != end[i]:
43+
if start[i] == end[i+1] and start[i+1] == end[i]:
44+
mid.append('-')
45+
tempc = start[i]
46+
start[i] = start[i + 1]
47+
start[i + 1] = tempc
48+
else:
49+
for finish in range(k-1):
50+
print('x', end='')
51+
52+
quit()
53+
else:
54+
mid.append('*')
55+
56+
for i in range(k-1):
57+
print(mid[i], end='')

cmkim/BaekJoon/백준_3055.py

Whitespace-only changes.

cmkim/BaekJoon/백준_4386.py

Lines changed: 48 additions & 0 deletions
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/BaekJoon/백준_5972.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
import heapq
3+
INF = 1e9
4+
n, m = map(int, input().split())
5+
arr = [[] * (n+1) for _ in range(n+1)]
6+
dis = [INF] * (n+1)
7+
8+
for _ in range(m):
9+
a, b, c = map(int, input().split())
10+
arr[a].append((b, c))
11+
arr[b].append((a, c))
12+
13+
def dijkstra(start):
14+
q = []
15+
heapq.heappush(q, (0, start)) #비용, 출발점
16+
dis[start] = 0
17+
while q:
18+
d, now = heapq.heappop(q)
19+
if dis[now] < d:
20+
continue
21+
for v, w in arr[now]: # 가려는 곳에대한 위치, 비용
22+
cost = d + w
23+
if cost < dis[v]:
24+
dis[v] = cost
25+
heapq.heappush(q, (cost, v))
26+
27+
dijkstra(1)
28+
print(dis[n])
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from _collections import deque
2+
3+
def solution(n, computers):
4+
answer = 0
5+
visited = [False for i in range(n)]
6+
for i in range(n):
7+
if visited[i] == False:
8+
bfs(n, computers, i, visited)
9+
answer += 1
10+
11+
return answer
12+
13+
def bfs(n, computers, i, visited):
14+
visited[i] = True
15+
q = deque()
16+
q.append(i)
17+
while len(q) > 0:
18+
now = q.popleft()
19+
visited[now] = True
20+
for connect in range(n):
21+
if connect != now and computers[now][connect] == 1:
22+
if visited[connect] == False:
23+
q.append(connect)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from _collections import deque
2+
3+
4+
def solution(numbers, target):
5+
answer = 0
6+
7+
q = deque()
8+
q.append((0, 0))
9+
10+
while q:
11+
value, index = q.popleft()
12+
13+
#print('value, index = ', value, index)
14+
15+
if index == len(numbers):
16+
if value == target:
17+
answer += 1
18+
19+
else:
20+
temp = numbers[index]
21+
q.append((value + temp, index + 1))
22+
q.append((value - temp, index + 1))
23+
24+
return answer
25+
26+
27+
#print(solution([1, 1, 1, 1, 1], 3))

0 commit comments

Comments
 (0)