Algorithm/Beakjoon 34

220921_[백준]_16967번 : 배열 복원하기_python

https://www.acmicpc.net/problem/16967 16967번: 배열 복원하기 크기가 H × W인 배열 A와 두 정수 X와 Y가 있을 때, 크기가 (H + X) × (W + Y)인 배열 B는 배열 A와 배열 A를 아래로 X칸, 오른쪽으로 Y칸 이동시킨 배열을 겹쳐 만들 수 있다. 수가 겹쳐지면 수가 합쳐 www.acmicpc.net 뇌절하고 0 들어간 부분만 골라서 풀어보려고 했다...테스트 케이스는 돌아감.. 더보기 h,w,x,y = list(map(int,input().split())) b_array = [ 0*(w+y) for _ in range(h+x)] for i in range(h+x): b_array[i] = list(map(int,input().split())) a_arr..

Algorithm/Beakjoon 2022.09.21

220919_[백준]_13335번 : 트럭_python

https://www.acmicpc.net/problem/13335 13335번: 트럭 입력 데이터는 표준입력을 사용한다. 입력은 두 줄로 이루어진다. 입력의 첫 번째 줄에는 세 개의 정수 n (1 ≤ n ≤ 1,000) , w (1 ≤ w ≤ 100) and L (10 ≤ L ≤ 1,000)이 주어지는데, n은 다리를 건너는 트 www.acmicpc.net Queue 이용 # n : 다리를 건너는 트럭의 수, w : 다리의 길이, L : 다리의 최대하중 n, w, l = map(int, input().split()) truck_list = list(map(int, input().split())) queue = [0] * w # 다리 cnt = 0 while queue: cnt += 1 queue.pop..

Algorithm/Beakjoon 2022.09.19

220916_[백준]_1292번 : 쉽게 푸는 문제_python

https://www.acmicpc.net/problem/1292 1292번: 쉽게 푸는 문제 첫째 줄에 구간의 시작과 끝을 나타내는 정수 A, B(1 ≤ A ≤ B ≤ 1,000)가 주어진다. 즉, 수열에서 A번째 숫자부터 B번째 숫자까지 합을 구하면 된다. www.acmicpc.net 범위 구현하다가 어차피 a, b의 범위가 1000이니까... len(arr) = 1036 46으로 그냥 전부 만들어버림 a, b = map(int,input().split()) arr = [0] for i in range(46): for j in range(i): arr.append(i) print(sum(arr[a:b+1]))

Algorithm/Beakjoon 2022.09.16

220916_[백준]_1547번 : 공_python

https://www.acmicpc.net/problem/1547 1547번: 공 첫째 줄에 컵의 위치를 바꾼 횟수 M이 주어지며, M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 M개의 줄에는 컵의 위치를 바꾼 방법 X와 Y가 주어지며, X번 컵과 Y번 컵의 위치를 서로 바꾸는 것 www.acmicpc.net 공이 떨어지는 경우는 고려를 안했는데 이왜통과? 나중에 다시... graph = [0, True, False, False] #print(graph) m = int(input()) for i in range(m): x, y = map(int,input().split()) graph[x], graph[y] = graph[y], graph[x] #print(graph) print(graph.inde..

Algorithm/Beakjoon 2022.09.16

220901_[백준]_10844번 : 쉬운 계단 수_python

https://www.acmicpc.net/problem/10844 10844번: 쉬운 계단 수 첫째 줄에 정답을 1,000,000,000으로 나눈 나머지를 출력한다. www.acmicpc.net 문제 잘 읽자 국어공부 다시하자 ''' n=2 일 때, dp[2] = [10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98] 0 => dp[길이:i][자리수:j] = dp[i - 1][1] = [10] = 1 1~8 => dp[길이:i][자리수:j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] = [[10, 12], [21, 23], [32, 34], [43, 45], [54, 56], [65, 67], [76, 78],..

Algorithm/Beakjoon 2022.09.01

210830_[백준]_알고리즘 기초_9093번 : 단어 뒤집기_python

https://www.acmicpc.net/problem/9093 9093번: 단어 뒤집기 첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 문장이 하나 주어진다. 단어의 길이는 최대 20, 문장의 길이는 최대 1000이다. 단어와 단어 사이에는 www.acmicpc.net n = int(input()) for i in range(n): sentence = list(input().split()) for j in sentence: print(j[::-1], end=' ')

Algorithm/Beakjoon 2021.08.30

210830_[백준]_알고리즘 기초_10828번 : 스택_python

https://www.acmicpc.net/problem/10828 10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 시간 초과 코드 n = int(input()) stack = list() for i in range(n): word = list(map(str,input().split())) if word[0] == 'push': stack.append(int(word[1])) elif word[0] == 'pop': if len(stack) == 0: print(-1) # pop() : 지운 ..

Algorithm/Beakjoon 2021.08.30

210825_[백준]_정렬_python

1181번 # 단어 정렬 n = int(input()) words = [str(input()) for i in range(n)] words = list(set(words)) # lambda : 익명함수 # lambda 인자(words의 인자) : 표현식((글자수, 글자)) # key = 정렬을 목적으로 하는 함수를 값으로 넣음 words.sort(key = lambda x : (len(x), x)) print('\n'.join(words)) 10814번 # 나이순 정렬 n = int(input()) m = [] for i in range(n): age, name = map(str, input().split()) age = int(age) m.append((age, name)) m.sort(key = la..

Algorithm/Beakjoon 2021.08.25

210824_[백준]_정렬_2108번 : 통계학(?)_python

ValueError: invalid literal for int() with base 10: '' 이거 해결 될 때까지는 계속 시간초과 뜰 듯.... 쓸 수가 없는데 어떻게 하냐고...... import statistics from collections import Counter n = int(input()) n_list = [int(input()) for i in range(n)] # 산술평균 print(int(round(statistics.mean(n_list),0))) # 중앙값 print(statistics.median(n_list)) # 최빈값...보다 하나 작은 값 k = Counter(n_list).most_common() if len(n_list) > 1 : if k[0][1] == k[1..

Algorithm/Beakjoon 2021.08.24