Skip to content

Commit 8d930df

Browse files
authored
Merge branch 'main' into kcm_09_06
2 parents 4a1a110 + 085af38 commit 8d930df

File tree

127 files changed

+1774
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1774
-4
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.idea/
2-
.DS_Store
2+
.DS_Store
3+
codingtest_JavaJobJava.iml
4+
.idea
5+
out

cmkim/BaekJoon/백준_1039.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
from _collections import deque
3+
from itertools import combinations
4+
import sys, copy
5+
6+
7+
def bfs():
8+
c = set()
9+
answer = 0
10+
qlen = len(q)
11+
while qlen:
12+
x = q.popleft()
13+
l = list(str(x))
14+
for i, j in d:
15+
s = copy.deepcopy(l)
16+
temp_i, temp_j = s[i], s[j]
17+
s[i], s[j] = temp_j, temp_i
18+
if s[0] == '0':
19+
continue
20+
nx = int(''.join(s))
21+
if nx not in c:
22+
answer = max(answer, nx)
23+
c.add(nx)
24+
q.append(nx)
25+
qlen -= 1
26+
return answer
27+
28+
29+
n, k = map(int, input().split())
30+
item = [i for i in range(len(str(n)))]
31+
d = list(combinations(item, 2))
32+
#print(d)
33+
q = deque()
34+
q.append(n)
35+
36+
ans = 0
37+
while k:
38+
ans = bfs()
39+
k -= 1
40+
if not ans:
41+
print(-1)
42+
else:
43+
print(ans)
44+

cmkim/BaekJoon/백준_1062.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
from itertools import combinations
3+
from string import ascii_lowercase
4+
5+
antatica = ['a', 'c', 'i', 'n', 't']
6+
7+
def brute_force(alpha, cnt):
8+
if cnt == k:
9+
temp = 0
10+
for i in range(n):
11+
flag = 0
12+
for j in range(len(check[i])):
13+
if not alphabet[]
14+
15+
n, k = map(int, input().split())
16+
if k < 5:
17+
print(0)
18+
return
19+
20+
arr = [list(map(str, input())) for _ in range(n)]
21+
alphabet = [False] * 26
22+
for i in range(5):
23+
alphabet[ord(antatica[i]) - ord('a')] = True
24+
print(alphabet)
25+
#teach = list(combinations(list(ascii_lowercase), k - 5))
26+
word = []
27+
for i in range(n):
28+
word.append(arr[i][4:-4])
29+
30+
for i in range(n):
31+
check = []
32+
33+
for j in range(len(word[i])):
34+
if word[i][j] not in antatica:
35+
check.append(word[i][j])
36+
check = set(check)
37+
38+
brute_force(0, 0)
39+
#for i in range(len(check)):

cmkim/BaekJoon/백준_1072.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def main():
2+
3+
x, y = map(int, input().split())
4+
5+
z = int(y * 100 / x)
6+
7+
if z >= 99:
8+
print(-1)
9+
return 0
10+
11+
answer = 1000000000
12+
start, end = 1, 1000000000
13+
while start <= end:
14+
mid = (start + end) // 2
15+
nextz = int((y + mid) * 100 / (x + mid))
16+
if z < nextz:
17+
if mid < answer:
18+
answer = mid
19+
end = mid - 1
20+
else:
21+
start = mid + 1
22+
23+
print(answer)
24+
main()

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/백준_1103.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from _collections import deque
2+
import sys
3+
sys.setrecursionlimit(10**6)
4+
n, m = map(int, input().split())
5+
6+
dx = [-1, 1, 0, 0]
7+
dy = [0, 0, -1, 1]
8+
9+
arr = [list(map(str, input())) for _ in range(n)]
10+
dp = [[0] * m for _ in range(n)]
11+
visited = [[0] * m for _ in range(n)] #dp 배열추가
12+
# q = deque()
13+
# q.append((0, 0, 1))# x, y 좌표와 움직인 횟수
14+
result = 0 # 가장 큰 값을 저장해줄 변수
15+
16+
def bfs(x, y, count):
17+
global result
18+
result = max(result, count)
19+
20+
for i in range(4):
21+
nx = x + dx[i] * int(arr[x][y])
22+
ny = y + dy[i] * int(arr[x][y])
23+
24+
if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and dp[nx][ny] < count + 1: #적은 이동횟수는 무시하는 조건 추가
25+
if visited[nx][ny]:
26+
print(-1)
27+
exit()
28+
else:
29+
dp[nx][ny] = count + 1
30+
visited[nx][ny] = 1
31+
bfs(nx, ny, count+1)
32+
visited[nx][ny] = 0
33+
34+
bfs(0, 0, 0)
35+
print(result + 1)
36+
37+
# while q:
38+
# x, y, count = q.popleft()
39+
#
40+
# if count > n*m: #무한 반복될때 종료조건
41+
# print(-1)
42+
# quit()
43+
# for i in range(4):
44+
# nx = x + dx[i] * int(arr[x][y])
45+
# ny = y + dy[i] * int(arr[x][y])
46+
#
47+
# if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and visited[nx][ny] < count: #적은 이동횟수는 무시하는 조건 추가
48+
# q.append((nx, ny, count+1))
49+
# visited[nx][ny] = count
50+
#
51+
#
52+
# for i in range(n):
53+
# for j in range(m):
54+
# result = max(result, visited[i][j])
55+
#
56+
# if result < n*m:
57+
# print(result + 1)
58+
# else:
59+
# print(-1)
60+
61+
62+
# bfs 함수 따로 뽑아서 하는거랑 메인에서 q 구현해서 하는거랑 대체 무슨 차이?
63+
# 밑에 1크게 시작하는거랑 무슨차이?
64+
'''
65+
def bfs(x, y, count):
66+
global result
67+
result = max(result, count)
68+
69+
for i in range(4):
70+
nx = x + dx[i] * int(arr[x][y])
71+
ny = y + dy[i] * int(arr[x][y])
72+
73+
if 0 <= nx < n and 0 <= ny < m and arr[nx][ny] != 'H' and dp[nx][ny] < count: #적은 이동횟수는 무시하는 조건 추가
74+
if visited[nx][ny]:
75+
print(-1)
76+
exit()
77+
else:
78+
dp[nx][ny] = count +1
79+
visited[nx][ny] = 1
80+
bfs(nx, ny, count+1)
81+
visited[nx][ny] = 0
82+
83+
bfs(0, 0, 1)
84+
print(result)
85+
'''

cmkim/BaekJoon/백준_1202.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import heapq
2+
import sys
3+
input = sys.stdin.readline
4+
n, k = map(int, input().split())
5+
6+
jewel = []
7+
bags = []
8+
9+
for i in range(n):
10+
w, v = map(int, input().split())
11+
heapq.heappush(jewel, (w, v))
12+
13+
for i in range(k):
14+
heapq.heappush(bags, int(input()))
15+
16+
result = 0
17+
selected = []
18+
for _ in range(k):
19+
bags_weight = heapq.heappop(bags)
20+
21+
while jewel and bags_weight >= jewel[0][0]:
22+
tmp = heapq.heappop(jewel)
23+
w, v = tmp[0], tmp[1]
24+
heapq.heappush(selected, -v)
25+
26+
if selected:
27+
result -= heapq.heappop(selected)
28+
29+
print(result)
30+
'''
31+
4 4
32+
1 100
33+
2 200
34+
13 300
35+
10 500
36+
14
37+
3
38+
12
39+
1
40+
'''

cmkim/BaekJoon/백준_1260.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from collections import deque
2+
def DFS(v, visited):
3+
4+
visited[v] = 1
5+
print(v, end = ' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능)
6+
7+
for i in range(1, n+1):
8+
9+
if not visited[i] and arr[v][i] == 1:
10+
DFS(i, visited)
11+
12+
def BFS(v, visited):
13+
queue = deque([v])
14+
visited[v] = 1
15+
16+
while(queue):
17+
v = queue.popleft() # 시작 기준이 되는 값을 잡고 시작한다.
18+
print(v, end=' ') # end= ' ' -> 다음 출력값 사이의 간격 조정(줄바꿈도 생략가능)
19+
for i in range(1, n+1): # 기준값 주변에 있는 방문하지 않은 값들을 전부 탐색한다.
20+
if not visited[i] and arr[v][i] == 1:
21+
queue.append(i)
22+
visited[i] = 1
23+
24+
25+
26+
n, m, v = map(int, input().split())
27+
28+
arr = [[0]*(n+1) for _ in range(n+1)]
29+
visited = [0]*(n+1)
30+
31+
for i in range(m):
32+
x, y = map(int, input().split())
33+
arr[x][y] = 1
34+
arr[y][x] = 1
35+
36+
37+
38+
39+
DFS(v, visited) #사용할 graph, 시작노드, 방문여부
40+
print('')
41+
visited = [0]*(n+1)
42+
BFS(v, visited)

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/백준_14476.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
n = int(input())
2+
arr = list(map(int, input().split()))

0 commit comments

Comments
 (0)