Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

36 pknujsp #143

Merged
merged 7 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pknujsp/BFS/33-이분 그래프.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import *
from collections import *


def bfs(start):
q = deque([start])
groups[start] = 1

while q:
curr = q.popleft()
visited[curr] = True

for adj in graph[curr]:
if visited[adj]:
continue

if not groups[adj]:
groups[adj] = -groups[curr]
q.append(adj)
elif groups[adj] == groups[curr]:
return False
return True


for _ in range(int(stdin.readline())):
V, E = map(int, stdin.readline().split())
graph = [[] for i in range(V + 1)]

for _ in range(E):
a, b = map(int, stdin.readline().split())
graph[a].append(b)
graph[b].append(a)

groups = [0] * (V + 1)
visited = [False] * (V + 1)
result = None

for i in range(1, V + 1):
if groups[i] == 0 and not bfs(i):
result = 'NO'
break

print('YES' if not result else result)
6 changes: 5 additions & 1 deletion pknujsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
| 29차시 | 2024.01.18 | DFS, UNION-FIND | [순열 사이클](https://www.acmicpc.net/problem/10451) | [#112](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/112) |
| 30차시 | 2024.01.23 | DP | [ABBC](https://www.acmicpc.net/problem/25381) | [#119](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/119) |
| 31차시 | 2024.01.30 | SORT | [멀티버스 Ⅱ](https://www.acmicpc.net/problem/18869) | [#123](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/123) |
| 32차시 | 2024.02.04 | BFS | [숨바꼭질 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) |
| 32차시 | 2024.02.04 | BFS | [숨바꼭질 3](https://www.acmicpc.net/problem/13549) | [#127](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/127) |
| 33차시 | 2024.02.06 | 큐 | [철로](https://www.acmicpc.net/problem/13334) | [#132](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/132) |
| 34차시 | 2024.02.12 | BFS | [이분 그래프](https://www.acmicpc.net/problem/1707) | [#135](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/135) |
| 35차시 | 2024.02.18 | 그리디 | [선물할인](https://www.acmicpc.net/problem/25947) | [#137](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/137) |
| 36차시 | 2024.02.21 | 이진탐색 | [휴게소 세우기](https://www.acmicpc.net/problem/1477) | [#143](https://github.com/lgoLeadMe/AlgoLeadMe-1/pull/143) |
36 changes: 36 additions & 0 deletions pknujsp/그리디/35-선물할인.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from sys import *

n, budget, max_sales = map(int, stdin.readline().split())
gifts = sorted(list(map(int, stdin.readline().split())))

min_price_gift = max_price_gift = 0
prices = 0
sales = 0

for sale_gift in range(max_sales):
prices += gifts[sale_gift] // 2
max_price_gift += 1

if prices > budget:
print(sale_gift)
exit()

sales = max_price_gift - min_price_gift
while max_price_gift < n:
if sales < max_sales or max_sales == 0:
if max_sales == 0:
prices += gifts[max_price_gift]
else:
prices += gifts[max_price_gift] // 2

if prices > budget:
break

max_price_gift += 1
sales += 1
else:
prices += gifts[min_price_gift] // 2
min_price_gift += 1
sales -= 1

print(max_price_gift)
30 changes: 30 additions & 0 deletions pknujsp/이진탐색/36-휴게소 세우기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
N, M, L = map(int, input().split())
array = list(map(int, input().split()))
array.sort()

left = 1
right = L - 1

min_max_distance = right

while left <= right:
max_distance = (left + right) // 2
extra_added = 0
last_installed_x = 0

for installed_x in array:
if installed_x - last_installed_x > max_distance:
extra_added += (installed_x - last_installed_x - 1) // max_distance

last_installed_x = installed_x

if L - last_installed_x > max_distance:
extra_added += (L - last_installed_x - 1) // max_distance

if extra_added > M:
left = max_distance + 1
else:
right = max_distance - 1

print(left)

28 changes: 28 additions & 0 deletions pknujsp/큐/33-철로.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from sys import *
from heapq import *

points = []

for _ in range(int(stdin.readline().strip())):
h, o = map(int, stdin.readline().strip().split())
points.append([min(h, o), max(h, o)])

points.sort(key=lambda x: x[1])
D = int(stdin.readline().strip())

max_users = 0
start_points_list = []

for start, destination in points:
if start + D < destination:
continue
heappush(start_points_list, start)

while start_points_list:
if start_points_list[0] + D >= destination:
break
heappop(start_points_list)

max_users = max(max_users, len(start_points_list))

print(max_users)