Skip to content

[23-10-08] jiwon.py #330

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions Baekjoon - 문제풀이/공유기 설치/jiwon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

N, C = map(int, sys.stdin.readline().split())
houses = [int(sys.stdin.readline()) for _ in range(N)]
houses.sort()

max_distance = houses[-1]-houses[0]
s,e = 1, max_distance
result = 0

while s<=e:
cur = houses[0]
temp = 1
m = (s+e)//2

for i in range(1,N):
if houses[i]-cur >= m:
cur = houses[i]
temp+=1

if temp >= C:
s = m+1
result = m
else:
e = m-1

print(result)
30 changes: 30 additions & 0 deletions Baekjoon - 문제풀이/스타트와 링크/jiwon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
from itertools import combinations

N = int(sys.stdin.readline())
values = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

total = [i for i in range(N)]
teams = list(combinations(total,N//2))
teams = teams[:len(teams)//2]
result = 100

for team in teams:
start = list(team)
link = [i for i in total if i not in start]

start_comb = list(combinations(start,2))
start_value = 0
for i,j in start_comb:
start_value+=values[i][j]
start_value+=values[j][i]

link_comb = list(combinations(link,2))
link_value = 0
for i,j in link_comb:
link_value+=values[i][j]
link_value+=values[j][i]

result = min(result, abs(start_value-link_value))

print(result)
59 changes: 59 additions & 0 deletions Baekjoon - 문제풀이/토마토/jiwon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sys

# M: 가로, N: 세로
# 1:익, 0:노익, -1:없음
M,N = map(int, sys.stdin.readline().split())
tomatos = []
all_1, cant_1 = True, True

for _ in range(N):
t = list(map(int, sys.stdin.readline().split()))
tomatos.append(t)

if all_1 and 0 in t:
all_1 = False
if cant_1 and 1 in t:
cant_1 = False

if all_1:
print(0)
exit(1)
if cant_1:
print(-1)
exit(1)

dx = [0,0,-1,1]
dy = [-1,1,0,0]

def bfs(x,y):
for i in range(4):
new_x = x+dx[i]
new_y = y+dy[i]

if new_x<0 or new_x>=M or new_y<0 or new_y>=N:
continue

if tomatos[new_y][new_x] == -1:
continue

tomatos[new_y][new_x] = 1
print(tomatos)

day = 0

while(True):
day+=1
do = False
for i in range(N):
for j in range(M):
if tomatos[i][j]==1:
bfs(j,i)

for tomato in tomatos:
if 0 in tomato:
do = True

if not do:
break

print(day)