Skip to content
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
13 changes: 13 additions & 0 deletions week16/BOJ_1_20115/정길연_20115.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
N = int(input())
drinks = list(map(int, input().split()))

drinks.sort()

ans = 0.0
while(len(drinks) != 1):
ans = drinks[0]/2 + drinks.pop()
drinks.append(ans)
if(len(drinks)) :
drinks.pop(0)

print(ans)
96 changes: 96 additions & 0 deletions week16/BOJ_2_12933/정길연_12933.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

# # # 차례대로 q, u, a, c, k가 나오는 경우 (겹쳐서를 고려하지 않음))
# ori = list(input())

# cnt = 0
# ans = 0

# for i in range(len(ori)):
# if cnt == 0 and ori[i] == "q":
# cnt += 1
# elif cnt == 1 and ori[i] == "u":
# cnt += 1
# elif cnt == 2 and ori[i] == "a":
# cnt +=1
# elif cnt == 3 and ori[i] == "c":
# cnt += 1
# elif cnt == 4 and ori[i] == "k":
# cnt = 0
# ans += 1
# else:
# continue

# if(ans == 0):
# print(-1)
# else:
# print(ans)


# 이렇게 하면 연속된 quack은 한마리로 인지하는 것이 아닌, 여러 마리로 인식됨
sound = list(input())
visited = [ 0 ] * len(sound)
ans = 0

if sound[0] != "q" or sound[-1] != "k" or len(sound) % 5 :
print(-1)
exit()

def find_uack(start) :
uack = "uack"
j = 0
global ans
for i in range(start, len(sound)):
if sound[i] == uack[j] and not visited[i]:
visited[i] = 1
if sound[i] == "k":
ans += 1
j = 0
continue # j 떄문에 continue로 꼭 끊어줘야함
j += 1

for i in range(len(sound) - 4): # 어차피 q 뒤에는 무조건 uack이 와야하므로 -4를 해준다
if sound[i] == "q" and not visited[i]:
visited[i] = 1
find_uack(i + 1)

if ans :
print(ans)
else :
print(-1)



sound = list(input())
ans = 0

if sound[0] != "q" or sound[-1] != "k" or len(sound) % 5 :
print(-1)
exit()

def find_quack(start) :
quack = "quack"
j = 0
global ans
new_ori = True # 새로운 오리로 생성하라는 flag
for i in range(start, len(sound)):
if sound[i] == quack[j]:
if sound[i] == "k":
if new_ori: # 새로운 오리일 경우, 오리(ans) 추가
ans += 1
new_ori = False # k값으로 끝났으니 새로운 오리를 생성하지 말라는 flag
j = 0 # 이어지는 "q" 탐색 - 새로운 오리가 아님 (현재 오리)
sound[i] = 0
continue
j += 1
sound[i] = 0


for i in range(len(sound) - 4): # 어차피 q 뒤에는 무조건 uack이 와야하므로 -4를 해준다
if sound[i] == "q" :
find_quack(i)


if any(sound) or ans == 0 :
print(-1)
else :
print(ans)
57 changes: 57 additions & 0 deletions week16/BOJ_3_21608/정길연_21608.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import sys
from collections import defaultdict

input = sys.stdin.readline
N = int(input())

arr = [ [0] * N for _ in range(N) ]
likedict = defaultdict(list)
result = 0

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

for _ in range(N*N):
_input = list(map(int, input().split()))
likedict[_input[0]] = _input[1:]

max_x = 0
max_y = 0
max_like = -1
max_empty = -1
for i in range(N):
for j in range(N):
if arr[i][j] == 0:
likecnt = 0
emptycnt = 0
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx < N and 0 <= ny < N:
if arr[nx][ny] in _input:
likecnt += 1
if arr[nx][ny] == 0:
emptycnt += 1

if max_like < likecnt or (max_like == likecnt and max_empty < emptycnt):
max_x = i
max_y = j
max_like = likecnt
max_empty = emptycnt

arr[max_x][max_y] = _input[0]

for i in range(N):
for j in range(N):
cnt = 0
likes = likedict[arr[i][j]]
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx < N and 0 <= ny < N:
if arr[nx][ny] in likes:
cnt += 1
if cnt != 0:
result += 10 ** (cnt - 1)

print(result)
37 changes: 37 additions & 0 deletions week16/BOJ_4_18352/정길연_18352.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections import deque
import sys

input = sys.stdin.readline

n, m, k, x = map(int, input().split())
graph = [[] for _ in range(n+1)]

distance = [0] * (n+1)
visited = [False] * (n+1)

for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)

def bfs(start):
answer = []
q = deque([start])
visited[start] = True
distance[start] = 0
while q:
now = q.popleft()
for i in graph[now]:
if not visited[i]:
visited[i] = True
q.append(i)
distance[i] = distance[now] + 1
if distance[i] == k:
answer.append(i)
if len(answer) == 0:
print(-1)
else:
answer.sort()
for i in answer:
print(i, end='\n')

bfs(x)
27 changes: 27 additions & 0 deletions week16/BOJ_5_21921/정길연_21921.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
n, x = map(int, input().split())
arr = list(map(int, input().split()))

if max(arr) == 0:
print("SAD")
else:
values = [0]
for i, a in enumerate(arr):
values.append(values[i] + a)

left = 0
right = x
result = 0
count = 0

while right <= n:
if right - left == x:
if result < values[right] - values[left]:
result = values[right] - values[left]
count = 1
elif result == values[right] - values[left]:
count += 1
left += 1
right += 1

print(result)
print(count)