Algorithm/Beakjoon 34

210823_[백준]_정렬_수 정렬하기_python

2750번, 2751번 # 2750(python), 2751(pypy3) n = int(input()) n_list = [int(input()) for i in range(n)] n_list.sort() for i in n_list: print(i) 10989번(X) # 메모리 초과(pypy3)...시간 초과(python)..시발... # 변수와 함수를 직접 제어할 수 있게 해주는 모듈 import sys # sys.stdin.readline() # n = int(sys.stdin.readline()) # ValueError: invalid literal for int() with base 10: '' # n = int(sys.stdin.readline().split(' ')) # TypeError: i..

Algorithm/Beakjoon 2021.08.24

210803_[백준]_브루트 포스_1018번 : 체스판 다시 칠하기(X)_python

n, m = map(int, input().split()) l = [] mini = [] for _ in range(n): l.append(input()) for a in range(n - 7): for i in range(m - 7): idx1 = 0 idx2 = 0 for b in range(a, a + 8): for j in range(i, i + 8): # 8X8 범위를 B와 W로 번갈아가면서 검사 if (j + b)%2 == 0: if l[b][j] != 'W': idx1 += 1 if l[b][j] != 'B': idx2 += 1 else : if l[b][j] != 'B': idx1 += 1 if l[b][j] != 'W': idx2 += 1 mini.append(idx1) # W로 시작했을..

Algorithm/Beakjoon 2021.08.03

210729_[백준]_브루트 포스_2231번 : 분해합_python

''' trial_1 : 정신차리자...거꾸로 구했잖ㅇ..어쩐지 쉽더라.. n = int(input()) s_list = list(str(n)) n_list = [] for i in range(len(s_list)): n_list.append(int(s_list[i])) print(n + sum(n_list)) ''' n = int(input()) result = 0 for i in range(1, n+1): # 1부터 n까지 div_n_list = list(map(int, str(i))) # 각 자리수 리스트 sum_n = i + sum(div_n_list) # 분해합 if sum_n == n: # 분해합 = n result = i # 네놈이다.. break print(result)

Algorithm/Beakjoon 2021.07.30

210729_[백준]_재귀_11729번 : 하노이탑(△)_python

# 하노이탑 = 2^n - 1 : 최소 횟수 ''' trial_1 : 틀렸습니다 def hanoi(n, start_poll, pass_poll, goal_poll): if n == 1: print(start_poll, goal_poll) else: hanoi(n-1, start_poll, goal_poll, pass_poll) print(start_poll, goal_poll) hanoi(n-1, pass_poll, start_poll, goal_poll) n = int(input()) print(2**n - 1) print(hanoi(n, 1, 2, 3)) ''' def hanoi(n, start_poll, pass_poll, goal_poll): if n == 1: # 원반이 하나면 바로 마지막 기둥..

Algorithm/Beakjoon 2021.07.29

210727_[백준]_재귀_2447번 : 별 찍기(△)_python

''' *** * * *** 이 모양이 반복되는 것, 프렉탈 생각하면 될 듯 ''' n = int(input()) stars = ['***', '* *', '***'] cnt = 0 while n > 3: # n이 3보다 클 경우 제곱수를 찾아내 cnt에 반영 n = n / 3 cnt += 1 def makeStar(): star_list = [] for i in range(len(stars)*3): if i // len(stars) == 1: # 가운데 빈칸 star_list.append(stars[i%len(stars)] + " "*len(stars) + stars[i%len(stars)]) else: # 빈칸 없이 첫 모양으로 채워넣음 star_list.append(stars[i%len(stars)..

Algorithm/Beakjoon 2021.07.27

210722_[백준]_기본 수학2_python

1085번 # 직사각형에서 탈출 ''' trial_1 : 틀렸습니다 x, y, w, h = map(int, input().split()) d_list = [] if x < w/2: d_list.append(x) else: d_list.append(w-x) if y < h/2: d_list.append(y) else: d_list.append(h-y) print(min(d_list)) ''' x, y, w, h = map(int, input().split()) print(min(x, y, w-x, h-y)) 3009번 # 네 번째 점 x_list = [] y_list = [] for i in range(3): x, y = map(int, input().split()) x_list.append(x) y_li..

Algorithm/Beakjoon 2021.07.22