Skip to content

찬민 백준숙제 #102

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

Merged
merged 2 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cmkim/BaekJoon/백준_10800.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys

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

ball = []
answer = [0] * n
color = [0] * 200001 # [0 for _ in range(200000)] #

for i in range(n):
c, s = map(int, input().split())
ball.append([i, c, s])

# print(ball)
ball.sort(key=lambda x: x[2]) # 사이즈, 컬러 순 오름차순
# print(ball)

j = 0
sum = 0
for i in range(n):
a = ball[i]
b = ball[j]

while b[2] < a[2]:
sum += b[2]
color[b[1]] += b[2]
j += 1
b = ball[j]

answer[a[0]] = sum - color[a[1]]

for i in range(n):
print(answer[i])
17 changes: 17 additions & 0 deletions cmkim/BaekJoon/백준_12927.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
arr = input()
n = len(arr)
light = [-1]
count = 0
for i in range(n):
if arr[i] == 'Y':
light.append(1)
else:
light.append(-1)

for i in range(1, n+1):
if light[i] == 1:
for j in range(i, n+1, i):
light[j] *= -1
count += 1

print(count)
19 changes: 19 additions & 0 deletions cmkim/BaekJoon/백준_1484.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
g = int(input())
a, b = 1, 2 #기억한 몸무게, 현재 몸무게

find = False
while a < 50002 and b < 50002:
if b**2 - a**2 == g:
print(b)
find = True
a += 1
b += 1
elif (b**2 - a**2) > g:
a += 1
else:
b += 1

if not find:
print(-1)

#시간이 왜 이렇게 오래 걸리는지?
37 changes: 37 additions & 0 deletions cmkim/BaekJoon/백준_1991.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def rab(node):
if node == '.':
return
print(node, end='')
rab(tree[node][0])
rab(tree[node][1])


def arb(node):
if node == '.':
return
arb(tree[node][0])
print(node, end='')
arb(tree[node][1])


def abr(node):
if node == '.':
return
abr(tree[node][0])
abr(tree[node][1])
print(node, end='')


n = int(input())
tree = {}

for _ in range(n):
root, left, right = input().split()
tree[root] = [left, right]

print(tree)
rab('A')
print('')
arb('A')
print('')
abr('A')
13 changes: 13 additions & 0 deletions cmkim/BaekJoon/백준_2533.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
input = sys.stdin.readline

n = int(input())
tree = [[] for _ in range(n+1)]
for i in range(n-1):
a, b = map(int, input().split())

tree[a].append(b)
tree[b].append(a)

print(tree)

60 changes: 60 additions & 0 deletions cmkim/BaekJoon/백준_2842.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import sys
from collections import deque
input = sys.stdin.readline
dx = [1, 0, -1, 0, -1, 1, 1, -1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

N = int(input())
map = [list(map(str, input().rstrip())) for _ in range(N)]
height = [[int(x) for x in input().split()] for _ in range(N)]
visited = [[0]*N for _ in range(N)]
houses = []
n_house = 0

# print(map)
# print(height)

def bfs(x, y, count):
q = deque()
q.append([x, y])
visited[x][y] = 1
count += 1
while q:
x, y = q.popleft()
for i in range(8):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny]:
visited[nx][ny] = 1
if height[nx][ny] < low:
low = height[nx][ny]
if height[nx][ny] < high:
high = height[nx][ny]
q.append([nx, ny])




for i in range(N):
for j in range(N):
if map[i][j] == 'P':
sx, sy = i, j #시작위치
houses.append([i, j])
n_house += 1
if map[i][j] == 'K':
houses.append([i, j])
n_house += 1
#print(type(height[1][1]))
# print(houses)
low, high = 1000000, 0


for i in range(n_house):

if height[houses[i][0]][houses[i][1]] < low:
low = height[houses[i][0]][houses[i][1]]

if height[houses[i][0]][houses[i][1]] > high:
high = height[houses[i][0]][houses[i][1]]

print('low, high = ', low, high)
46 changes: 46 additions & 0 deletions cmkim/그렙 채용 챌린지/1번문제.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
def solution(arr):
arr.sort()
dp = [0 for _ in range(255)]
for i in range(0, 255):
under, over = 0, 0
for num in arr:
if i > num:
under += 1
else:
over += 1
dp[i] = abs(under - over)

for i in range(0, 255):
if dp[i] == min(dp):
answer = i

# left = min(arr)
# right = max(arr)
# diff = len(arr)
# print(diff)
# under, over = 0, 0
# while left < right:
# mid = (left + right) // 2
# for i in range(0, len(arr)):
# if mid < arr[i]:
# under = i
# over = len(arr) - i
# print('under, over = ', under, over)
# if abs(under - over) <= diff:
# diff = abs(under - over)
# answer = mid
# if under > over:
# right = mid - 1
# break
# elif under < over:
# left = mid + 1
# break
# else:
# right -= 2
# break
#
# return answer


arr =[0, 0, 255, 255, 0, 0, 255, 255, 255]
solution(arr)
36 changes: 36 additions & 0 deletions cmkim/그렙 채용 챌린지/2번문제.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def solution(card_numbers):
answer = []
for card in card_numbers:
arr = card.split('-')
result = 0
#print(arr)
valid = 1
print(len(arr))
if len(arr) == 4:
for i in range(4):
if len(arr[i]) != 4:
valid = 0

if valid == 0:
answer.append(0)
continue

for i in range(4):
for j in range(4):
result += int(arr[i][j])
if j%2 == 0:
result += int(arr[i][j])
if result % 10 == 0:
answer.append(1)
else:
answer.append(0)
else:
for i in range(16):
result += int(arr[i])
if i % 2 == 0:
result += int(arr[i])
if result % 10 == 0:
answer.append(1)
else:
answer.append(0)
return answer