-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c07276
Showing
124 changed files
with
2,864 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
x = int(input()) | ||
|
||
d = [0] * 30001 | ||
|
||
for i in range(2, x+1): | ||
d[i] = d[i-1] + 1 | ||
if i % 2 == 0: | ||
d[i] = min(d[i], d[i//2]+1) | ||
if i % 3 == 0: | ||
d[i] = min(d[i], d[i//3]+1) | ||
if i % 5 == 0: | ||
d[i] = min(d[i], d[i//5]+1) | ||
|
||
print(d[x]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# n이 1이 되는 최소 횟수 | ||
# n에서 1을 빼거나 n을 k로 나누거나 | ||
n, k = map(int, input().split()) | ||
count = 0 | ||
''' | ||
while True: | ||
if n == 1: | ||
break | ||
if n%k == 0: | ||
n = n / k | ||
count += 1 | ||
else: | ||
n -= 1 | ||
count += 1 | ||
print(count) | ||
''' | ||
|
||
# 최대한 많이 나누기 | ||
while True: | ||
# 나누어 떨어질 때까지 1씩 빼기 | ||
target = (n//k) * k | ||
count += (n-target) | ||
n = target | ||
if n < k: # 더 이상 나눌 수 없을 때 | ||
break | ||
count += 1 | ||
n //= k | ||
|
||
count += (n-1) # n을 0으로 만들었기 때문 | ||
print(count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 시간초과 -> REVERSE의 횟수 줄이기 | ||
import sys | ||
from collections import deque | ||
input = sys.stdin.readline | ||
|
||
T = int(input()) | ||
for _ in range(T): | ||
p = input() | ||
p = p.replace("RR", "") | ||
n = int(input()) | ||
x = input().rstrip()[1:-1].split(",") | ||
if x[0] == '': x = deque() | ||
else: x = deque(x) | ||
|
||
error = 0 | ||
reverse = 0 | ||
for i in range(len(p)): | ||
if p[i] == "R": | ||
reverse += 1 | ||
elif p[i] == "D": | ||
if len(x) == 0: | ||
print("error") | ||
error = 1 | ||
break | ||
else: | ||
if reverse%2 == 0: | ||
x.popleft() | ||
else: | ||
x.pop() | ||
|
||
if not error: | ||
if reverse % 2 != 0: x.reverse() | ||
print('[', end='') | ||
print(*x, sep=',', end='') | ||
print(']') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 돈을 인출하는데 필요한 시간의 합의 최솟값 | ||
n = int(input()) | ||
time = list(map(int, input().split())) | ||
|
||
# 순서의 가능한 형태 n! | ||
# n!경우를 모두 계산? | ||
# => 시간이 적게 걸리는 사람을 앞으로 ... 정렬 | ||
# 각각의 원소를 (list의 length - index)번 더함 | ||
time.sort() | ||
result = 0 | ||
for i in range(len(time)): | ||
result += (len(time)-i) * time[i] | ||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from collections import deque | ||
|
||
def bfs(graph, start, visited): | ||
queue = deque([start]) | ||
visited[start] = True | ||
|
||
while queue: | ||
v = queue.popleft() | ||
print(v, end = ' ') | ||
|
||
for i in graph[v]: | ||
if not visited[i]: | ||
queue.append(i) | ||
visited[i] = True | ||
|
||
graph = [ | ||
[], | ||
[2, 3, 8], | ||
[1, 7], | ||
[1, 4, 5], | ||
[3, 5], | ||
[3, 4], | ||
[7], | ||
[2, 6, 8], | ||
[1, 7] | ||
] | ||
|
||
visited = [False] * 9 | ||
|
||
bfs(graph, 1, visited) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def dfs(graph, v, visited): | ||
visited[v] = True | ||
print(v, end = ' ') | ||
|
||
for i in graph[v]: | ||
if not visited[i]: | ||
dfs(graph, i, visited) | ||
|
||
graph = [ | ||
[], | ||
[2, 3, 8], | ||
[1, 7], | ||
[1, 4, 5], | ||
[3, 5], | ||
[3, 4], | ||
[7], | ||
[2, 6, 8], | ||
[1, 7] | ||
] | ||
|
||
visited = [False] * 9 | ||
|
||
dfs(graph, 1, visited) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 너비 우선 탐색 | ||
# 뒤집기 연산을 이용한 정렬 | ||
# 배열의 길이가 1<=n<=8 | ||
import sys | ||
from collections import deque | ||
|
||
|
||
def bfs(start, length): | ||
queue = deque() | ||
queue.append((start, 0)) | ||
dp['12345678'] = 0 | ||
|
||
while queue: | ||
now, level = queue.popleft() | ||
|
||
for i in range(len(now)): | ||
for j in range(i+1, len(now)): | ||
now[i:j+1] = now[i:j+1][::-1] # [::-1] 역순으로 | ||
string = "".join(now) | ||
|
||
if dp.get(string) is None: | ||
queue.append((list(now), level+1)) | ||
dp[string] = level+1 | ||
|
||
now[i:j+1] = now[i:j+1][::-1] | ||
|
||
|
||
T = int(sys.stdin.readline().rstrip()) | ||
dp = {} # dictionary | ||
|
||
array = [str(num+1) for num in range(8)] | ||
bfs(array, len(array)) | ||
|
||
for _ in range(T): | ||
N = int(sys.stdin.readline().rstrip()) | ||
array = list(map(int, sys.stdin.readline().rstrip().split())) | ||
|
||
sorted_arr = list(sorted(array)) | ||
mapped = dict(zip(sorted_arr, range(1, N+1))) | ||
|
||
array = [mapped[num] for num in array] | ||
array = array + [num+1 for num in range(len(array), 8)] | ||
key = "".join(map(str, array)) | ||
print(dp[key]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import math | ||
|
||
n = 1000 | ||
array = [True for i in range(n + 1)] | ||
|
||
for i in range(2, int(math.sqrt(n)) + 1): | ||
if array[i]: | ||
j = 2 | ||
while i * j <= n: | ||
array[i * j] = False | ||
j += 1 | ||
|
||
for i in range(2, n + 1): | ||
if array[i]: | ||
print(i, end=' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import heapq | ||
|
||
def minheapsort(iterable): | ||
h = [] | ||
result = [] | ||
for value in iterable: | ||
heapq.heappush(h, value) | ||
for _ in range(len(h)): | ||
result.append(heapq.heappop(h)) | ||
return result | ||
|
||
def maxheapsort(iterable): | ||
h = [] | ||
result = [] | ||
for value in iterable: | ||
heapq.heappush(h, -value) | ||
for _ in range(len(h)): | ||
result.append(-heapq.heappop(h)) | ||
return result | ||
|
||
minresult = minheapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) | ||
maxresult = maxheapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) | ||
print(minresult) | ||
print(maxresult) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
""" | ||
1, 2, 3 ... 을 계속 더해 나갈 때, | ||
그 합이 입력한 정수(0 ~ 1000)보다 같거나 작을 때까지만 | ||
계속 더하는 프로그램을 작성해보자. | ||
즉, 1부터 n까지 정수를 계속 더해 나간다고 할 때, | ||
어디까지 더해야 입력한 수보다 같거나 커지는 지를 알아보고자하는 문제이다. | ||
n = int(input()) | ||
sum = 0 | ||
i = 1 | ||
while n > sum: | ||
sum += i | ||
i += 1 | ||
print(i-1) | ||
""" | ||
""" | ||
## 16진법 구구단 | ||
n = int(input(), 16) | ||
for i in range(1, 16): | ||
print('%X'%n, '*%X'%i, '=%X'%(n*i), sep ='') | ||
""" | ||
""" | ||
###1 부터 그 수까지 순서대로 공백을 두고 수를 출력하는데, | ||
###3 또는 6 또는 9가 포함 되어있는 수인 경우, 그 수 대신 영문 대문자 X 를 출력한다. | ||
###33과 같이 3,6,9가 두 번 들어간 수 일때, "짝짝"과 같이 박수를 두 번 치는 형태도 있다. => str.count() | ||
n = int(input()) | ||
for i in range(1, n+1): | ||
if i%10 == 3 or i%10 == 6 or i%10 == 9: | ||
print("X", end =" ") | ||
else: | ||
print(i, end=" ") | ||
""" | ||
""" | ||
a, m, d, n = input().split() | ||
a = int(a) | ||
m = int(m) | ||
d = int(d) | ||
n = int(n) | ||
for i in range(1, n): | ||
a = a * m + d | ||
print(a) | ||
""" | ||
""" | ||
d = [] | ||
for i in range(20): | ||
d.append([]) | ||
for j in range(20): | ||
d[i].append(0) | ||
n = int(input()) | ||
for i in range(n): | ||
x, y = input().split() | ||
d[int(x)][int(y)] = 1 | ||
for i in range(1, 20): | ||
for j in range(1, 20): | ||
print(d[i][j], end=" ") | ||
print() | ||
""" | ||
""" | ||
### 십자 뒤집기 | ||
d=[] | ||
for i in range(20): ## list 생성 후 모두 0을 채워 넣음 | ||
d.append([]) | ||
for j in range(20): | ||
d[i].append(0) | ||
for i in range(19): ## 입력을 첫 줄 부터 차례로 list에 저장 | ||
a = input().split() | ||
for j in range(19): | ||
d[i+1][j+1] = int(a[j]) | ||
n = int(input()) ## 십자 뒤집기 횟수 | ||
for i in range(n): | ||
x,y=input().split() | ||
x=int(x) | ||
y=int(y) | ||
for j in range(1, 20): ## 가로줄 뒤집기 | ||
if d[j][y]==0: | ||
d[j][y]=1 | ||
else: | ||
d[j][y]=0 | ||
if d[x][j]==0: ## 세로줄 뒤집기 | ||
d[x][j]=1 | ||
else: | ||
d[x][j]=0 | ||
for i in range(1, 20): ## 변경된 바둑판 출력 | ||
for j in range(1, 20): | ||
print(d[i][j], end=' ') | ||
print() | ||
""" | ||
""" | ||
### 설탕과자 놓기 | ||
h,w = input().split() | ||
h = int(h) | ||
w = int(w) | ||
m = [] | ||
for i in range(h+1): | ||
m.append([]) | ||
for j in range(w+1): | ||
m[i].append(0) | ||
n = int(input()) | ||
for i in range(n): | ||
l,d,x,y = input().split() | ||
if int(d)==0: | ||
for j in range(int(l)): | ||
m[int(x)][int(y)+j] = 1 | ||
else: | ||
for j in range(int(l)): | ||
m[int(x)+j][int(y)] = 1 | ||
for i in range(1, h+1): | ||
for j in range(1, w+1): | ||
print(m[i][j], end=' ') | ||
print() | ||
""" | ||
|
||
### 성실한 개미 | ||
m = [] | ||
for i in range(12): ## 리스트 생성 | ||
m.append([]) | ||
for j in range(12): | ||
m[i].append(0) | ||
for i in range(10): ## input 저장 | ||
a = input().split() | ||
for j in range(10): | ||
m[i+1][j+1] = int(a[j]) | ||
x = 2 ## 출발점(2,2) | ||
y = 2 | ||
while True: | ||
if m[x][y] == 0: ## 벽이 아니면 이동 가능 | ||
m[x][y] = 9 ## 경로에 9를 출력 | ||
elif m[x][y] == 2: | ||
m[x][y] = 9 | ||
break ## 목적지에 도착하면 종료 | ||
if (m[x][y+1]==1 and m[x+1][y]==1) or (x==9 and y==9): ## 더이상 움직일 수 없을 때 종료 | ||
break | ||
if m[x][y+1] != 1: ## 오른쪽에 길이 있으면 오른쪽으로 이동 | ||
y += 1 | ||
elif m[x+1][y] != 1: ## 오른쪽에 길이 없고 아래에 길이 있으면 아래로 이동 | ||
x += 1 | ||
for i in range(1, 11): ## 결과 출력 | ||
for j in range(1, 11): | ||
print(m[i][j], end=' ') | ||
print() | ||
|
Oops, something went wrong.