Skip to content

Commit 6ec266b

Browse files
authored
찬민 백준숙제 (#102)
* 찬민 백준숙제 * '8/27백준숙제'
1 parent 2e59bf3 commit 6ec266b

File tree

8 files changed

+261
-0
lines changed

8 files changed

+261
-0
lines changed

cmkim/BaekJoon/백준_10800.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
n = int(input())
5+
6+
ball = []
7+
answer = [0] * n
8+
color = [0] * 200001 # [0 for _ in range(200000)] #
9+
10+
for i in range(n):
11+
c, s = map(int, input().split())
12+
ball.append([i, c, s])
13+
14+
# print(ball)
15+
ball.sort(key=lambda x: x[2]) # 사이즈, 컬러 순 오름차순
16+
# print(ball)
17+
18+
j = 0
19+
sum = 0
20+
for i in range(n):
21+
a = ball[i]
22+
b = ball[j]
23+
24+
while b[2] < a[2]:
25+
sum += b[2]
26+
color[b[1]] += b[2]
27+
j += 1
28+
b = ball[j]
29+
30+
answer[a[0]] = sum - color[a[1]]
31+
32+
for i in range(n):
33+
print(answer[i])

cmkim/BaekJoon/백준_12927.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
arr = input()
2+
n = len(arr)
3+
light = [-1]
4+
count = 0
5+
for i in range(n):
6+
if arr[i] == 'Y':
7+
light.append(1)
8+
else:
9+
light.append(-1)
10+
11+
for i in range(1, n+1):
12+
if light[i] == 1:
13+
for j in range(i, n+1, i):
14+
light[j] *= -1
15+
count += 1
16+
17+
print(count)

cmkim/BaekJoon/백준_1484.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
g = int(input())
2+
a, b = 1, 2 #기억한 몸무게, 현재 몸무게
3+
4+
find = False
5+
while a < 50002 and b < 50002:
6+
if b**2 - a**2 == g:
7+
print(b)
8+
find = True
9+
a += 1
10+
b += 1
11+
elif (b**2 - a**2) > g:
12+
a += 1
13+
else:
14+
b += 1
15+
16+
if not find:
17+
print(-1)
18+
19+
#시간이 왜 이렇게 오래 걸리는지?

cmkim/BaekJoon/백준_1991.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
def rab(node):
2+
if node == '.':
3+
return
4+
print(node, end='')
5+
rab(tree[node][0])
6+
rab(tree[node][1])
7+
8+
9+
def arb(node):
10+
if node == '.':
11+
return
12+
arb(tree[node][0])
13+
print(node, end='')
14+
arb(tree[node][1])
15+
16+
17+
def abr(node):
18+
if node == '.':
19+
return
20+
abr(tree[node][0])
21+
abr(tree[node][1])
22+
print(node, end='')
23+
24+
25+
n = int(input())
26+
tree = {}
27+
28+
for _ in range(n):
29+
root, left, right = input().split()
30+
tree[root] = [left, right]
31+
32+
print(tree)
33+
rab('A')
34+
print('')
35+
arb('A')
36+
print('')
37+
abr('A')

cmkim/BaekJoon/백준_2533.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input())
5+
tree = [[] for _ in range(n+1)]
6+
for i in range(n-1):
7+
a, b = map(int, input().split())
8+
9+
tree[a].append(b)
10+
tree[b].append(a)
11+
12+
print(tree)
13+

cmkim/BaekJoon/백준_2842.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
dx = [1, 0, -1, 0, -1, 1, 1, -1]
5+
dy = [0, 1, 0, -1, 1, 1, -1, -1]
6+
7+
N = int(input())
8+
map = [list(map(str, input().rstrip())) for _ in range(N)]
9+
height = [[int(x) for x in input().split()] for _ in range(N)]
10+
visited = [[0]*N for _ in range(N)]
11+
houses = []
12+
n_house = 0
13+
14+
# print(map)
15+
# print(height)
16+
17+
def bfs(x, y, count):
18+
q = deque()
19+
q.append([x, y])
20+
visited[x][y] = 1
21+
count += 1
22+
while q:
23+
x, y = q.popleft()
24+
for i in range(8):
25+
nx = x + dx[i]
26+
ny = y + dy[i]
27+
if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny]:
28+
visited[nx][ny] = 1
29+
if height[nx][ny] < low:
30+
low = height[nx][ny]
31+
if height[nx][ny] < high:
32+
high = height[nx][ny]
33+
q.append([nx, ny])
34+
35+
36+
37+
38+
for i in range(N):
39+
for j in range(N):
40+
if map[i][j] == 'P':
41+
sx, sy = i, j #시작위치
42+
houses.append([i, j])
43+
n_house += 1
44+
if map[i][j] == 'K':
45+
houses.append([i, j])
46+
n_house += 1
47+
#print(type(height[1][1]))
48+
# print(houses)
49+
low, high = 1000000, 0
50+
51+
52+
for i in range(n_house):
53+
54+
if height[houses[i][0]][houses[i][1]] < low:
55+
low = height[houses[i][0]][houses[i][1]]
56+
57+
if height[houses[i][0]][houses[i][1]] > high:
58+
high = height[houses[i][0]][houses[i][1]]
59+
60+
print('low, high = ', low, high)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
def solution(arr):
2+
arr.sort()
3+
dp = [0 for _ in range(255)]
4+
for i in range(0, 255):
5+
under, over = 0, 0
6+
for num in arr:
7+
if i > num:
8+
under += 1
9+
else:
10+
over += 1
11+
dp[i] = abs(under - over)
12+
13+
for i in range(0, 255):
14+
if dp[i] == min(dp):
15+
answer = i
16+
17+
# left = min(arr)
18+
# right = max(arr)
19+
# diff = len(arr)
20+
# print(diff)
21+
# under, over = 0, 0
22+
# while left < right:
23+
# mid = (left + right) // 2
24+
# for i in range(0, len(arr)):
25+
# if mid < arr[i]:
26+
# under = i
27+
# over = len(arr) - i
28+
# print('under, over = ', under, over)
29+
# if abs(under - over) <= diff:
30+
# diff = abs(under - over)
31+
# answer = mid
32+
# if under > over:
33+
# right = mid - 1
34+
# break
35+
# elif under < over:
36+
# left = mid + 1
37+
# break
38+
# else:
39+
# right -= 2
40+
# break
41+
#
42+
# return answer
43+
44+
45+
arr =[0, 0, 255, 255, 0, 0, 255, 255, 255]
46+
solution(arr)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def solution(card_numbers):
2+
answer = []
3+
for card in card_numbers:
4+
arr = card.split('-')
5+
result = 0
6+
#print(arr)
7+
valid = 1
8+
print(len(arr))
9+
if len(arr) == 4:
10+
for i in range(4):
11+
if len(arr[i]) != 4:
12+
valid = 0
13+
14+
if valid == 0:
15+
answer.append(0)
16+
continue
17+
18+
for i in range(4):
19+
for j in range(4):
20+
result += int(arr[i][j])
21+
if j%2 == 0:
22+
result += int(arr[i][j])
23+
if result % 10 == 0:
24+
answer.append(1)
25+
else:
26+
answer.append(0)
27+
else:
28+
for i in range(16):
29+
result += int(arr[i])
30+
if i % 2 == 0:
31+
result += int(arr[i])
32+
if result % 10 == 0:
33+
answer.append(1)
34+
else:
35+
answer.append(0)
36+
return answer

0 commit comments

Comments
 (0)