Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Feb 23, 2021
1 parent ca90a5d commit 68bbd99
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 27 deletions.
15 changes: 15 additions & 0 deletions argorithm/10250.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
T = int(input())
for i in range(T):
H, W, N = map(int, input().split())
cnt = 0
for i in range(W):
for j in range(H):
cnt += 1
if cnt == N:
if i+1 > 9:
print(str(j+1)+str(i+1))
break
else:
print(str(j+1)+'0'+str(i+1))
break

7 changes: 7 additions & 0 deletions argorithm/10816.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
N = int(input())
N_list = list(map(int, input().split()))
M = int(input())
M_list = list(map(int, input().split()))

for ml in M_list:
print(N_list.count(ml), end=' ')
20 changes: 20 additions & 0 deletions argorithm/10816_re.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
N = int(input())
N_list = sorted(list(map(int, input().split())))
M = int(input())
M_list = list(map(int, input().split()))

for ml in M_list:
start=0
answer = 0
end=len(N_list)-1
while start <= end:
mid = (start+end)//2
if ml < N_list[mid]:
end = mid-1
elif ml > N_list[mid]:
start = mid+1
else:
answer += 1
N_list[mid] = 0
N_list.sort()
print(answer, end=' ')
13 changes: 13 additions & 0 deletions argorithm/10816_rere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
N = int(input())
N_list = sorted(list(map(int, input().split())))
M = int(input())
M_list = list(map(int, input().split()))

hashmap = {}
for n in N_list:
if n in hashmap:
hashmap[n] += 1
else:
hashmap[n] = 1

print(' '.join(str(hashmap[m]) if m in hashmap else '0' for m in M_list))
8 changes: 8 additions & 0 deletions argorithm/10816rerere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from collections import Counter
N = int(input())
N_list = input().split()
M = int(input())
M_list = input().split()

C = Counter(N_list)
print(' '.join(f'{C[m]}' if m in C else '0' for m in M_list))
24 changes: 24 additions & 0 deletions argorithm/10816rererere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
N = int(input())
N_list = sorted(list(map(int, input().split())))
M = int(input())
M_list = list(map(int, input().split()))


def binary(n, N, start, end):
while start <= end:
mid = (start+end)//2
if n==N[mid]:
return N[start:end+1].count(n)
elif n<N[mid]:
return binary(n, N, start, mid-1)
else:
return binary(n, N, mid+1, end)

n_dict = {}
for n in N_list:
start=0
end=len(N_list)-1
if n not in n_dict:
n_dict[n] = binary(n, N_list, start, end)

print(' '.join(str(n_dict[x]) if x in n_dict else '0' for x in M_list))
23 changes: 23 additions & 0 deletions argorithm/10828.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from collections import deque
import sys
input = sys.stdin.readline
q = deque()

N = int(input())
for _ in range(N):
val = input().rstrip()
if ' ' in val:
comm, num = val.split()
if comm == 'push':
q.append(num)
elif val == 'pop':
if len(q)==0: print(-1)
else: print(q.pop())
elif val == 'size':
print(len(q))
elif val == 'empty':
if len(q)==0: print(1)
else: print(0)
else:
if len(q)==0: print(-1)
else: print(q[-1])
7 changes: 7 additions & 0 deletions argorithm/1085.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# x, y를 함께 min 고려해주는 이유는 x, y좌표를 기준으로 w, h까지의 거리와
# (0, 0)까지의 거리를 고려해야하기 때문입니다.
# 예시 = (1 2 5 4) 이면 답은 1이어야 합니다.

x, y, w, h = map(int, input().split())

print(min(x, y, w-x, h-y))
20 changes: 19 additions & 1 deletion argorithm/11050.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
N, K = map(int, input().split())
N, K = map(int, input().split())
if N-K > 0:
M = N-K
else:
M = 1

C_N = 1
for i in range(1, N+1):
C_N*=i

C_M = 1
for j in range(1, M+1):
C_M*=j

C_K = 1
for a in range(1, K+1):
C_K*=a

print(int(C_N/(C_M*C_K)))
7 changes: 7 additions & 0 deletions argorithm/11650.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]

answer = sorted(arr, key=lambda x: (x[0], x[1]))

for a, b in answer:
print(a, b)
20 changes: 20 additions & 0 deletions argorithm/11866.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys
input = sys.stdin.readline

N, K = map(int, input().split())

answer = []
arr = [i for i in range(1, N+1)]

cnt = 0
while len(arr) != len(answer):
index = cnt%N
print('index: ', index)
if arr[index]==0:
index += 1
continue
cnt += 1
if (cnt % K) == 0:
answer.append(arr[(cnt%N)-1])
arr[(cnt%N)-1] = 0
print(answer)
17 changes: 17 additions & 0 deletions argorithm/11866_re.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from collections import deque
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
q = deque([])
for i in range(1, N+1):
q.append(i)

print('<', end='')
while q:
for i in range(K-1):
q.append(q[0])
q.popleft()
print(q.popleft(), end='')
if q:
print(',', end=' ')
print('>', end='')
18 changes: 18 additions & 0 deletions argorithm/14499.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
input = sys.stdin.readline

N, M, x, y, cnt = map(int, input().split())

map_list = [list(map(int, input().split())) for _ in range(N)]
move_list = list(map(int, input().split()))
dice = {1:0, 2:0, 3:0, 4:0, 5:0, 6:0}
for m in move_list:
# 주사위 굴리기 & 복사
if m==1: # 동
dice[4], dice[1], dice[3], dice[6] = dice[6], dice[4], dice[1], dice[3]
elif m==2: # 서
dice[4], dice[1], dice[3], dice[6] = dice[1], dice[3], dice[6], dice[4]
elif m==3: # 남
dice[2], dice[1], dice[5], dice[6] = dice[1], dice[5], dice[6], dice[2]
else: # 북
dice[2], dice[1], dice[5], dice[6] =
52 changes: 34 additions & 18 deletions argorithm/2751_병합.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,38 @@
N = int(input())
arr = [int(input()) for _ in range(N)]

def mergeSort(x):
if len(x) > 1:
mid = len(x)//2
lx, rx = x[:mid], x[mid:]
mergeSort(lx)
mergeSort(rx)
def mergeSort(array):
if len(array) <= 1:
return array
mid = len(array)//2
left = mergeSort(array[:mid])
print('left : ', left)
right = mergeSort(array[mid:])
print('right : ', right)

li, ri, i = 0, 0, 0
while li < len(lx) and ri < len(rx):
if lx[li] < rx[ri]:
x[i] = lx[li]
li += 1
else:
x[i] = rx[ri]
ri += 1
i += 1
x[i:] = lx[li:] if li != len(lx) else rx[ri:]
print(x)
mergeSort(arr)
i, j, k = 0, 0, 0

while i<len(left) and j<len(right):
if left[i] < right[j]:
array[k] = left[i]
i+=1
else:
array[k] = right[j]
j+=1
k+=1

if i==len(left):
while j<len(right):
array[k] = right[j]
j+=1
k+=1
elif j==len(right):
while i<len(left):
array[k] = left[i]
i+=1
k+=1
return array

answer = mergeSort(arr)
for i in answer:
print(i)
16 changes: 16 additions & 0 deletions argorithm/2798.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from itertools import combinations
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
arr = list(map(int, input().split()))

comb_list = list(combinations(arr, 3))

max = -1
for c in comb_list:
if sum(c) <= M and sum(c) > max:
max = sum(c)

print(max)

12 changes: 4 additions & 8 deletions argorithm/ground_picking.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
def solution(land):
n = len(land)-1
for i in range(n):
land[i+1][0] += max(land[i][1], land[i][2], land[i][3])
land[i+1][1] += max(land[i][0], land[i][2], land[i][3])
land[i+1][2] += max(land[i][0], land[i][1], land[i][3])
land[i+1][3] += max(land[i][0], land[i][1], land[i][2])
return max(land[n][0], land[n][1], land[n][2], land[n][3])

for i in range(1, len(land)):
for j in range(len(land[0])):
land[i][j] = max(land[i-1][:j] + land[i-1][j+1:]) +land[i][j]
return max(land[-1])

if __name__ == '__main__':
real_answer = solution([[1,2,3,5],[5,6,7,8],[4,3,2,1]])
Expand Down
20 changes: 20 additions & 0 deletions argorithm/기능개발.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import math

def solution(progresses, speeds):
answer = []
temp = []
for index, p in enumerate(progresses):
val = math.ceil((100-p)/speeds[index])
temp.append(val)

k = 0
for i in range(len(temp)):
if temp[i] > temp[k]:
answer.append(i-k)
k=i
answer.append(len(temp)-k)
return answer

if __name__ == '__main__':
result = solution([93, 30, 55], [1, 30, 5])
print(result)
20 changes: 20 additions & 0 deletions argorithm/기능개발_re.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def solution(progresses, speeds):
answer = []
time = 0
count = 0
while len(progresses)>0:
if (progresses[0] + time*speeds[0]) >= 100:
progresses.pop(0)
speeds.pop(0)
count += 1
else:
if count > 0:
answer.append(count)
count = 0
time += 1
answer.append(count)
return answer

if __name__ == '__main__':
result = solution([93, 30, 55], [1, 30, 5])
print(result)

0 comments on commit 68bbd99

Please sign in to comment.