문제풀이 324

[백준][백트래킹] 2580. 스도쿠 (파이썬/Python)

import sys r = sys.stdin.readline # 가로 체크 def horizontal(x, val): if val in sudoku[x]: return False return True # 세로 체크 def vertical(y, val): for i in range(9): if val == sudoku[i][y]: return False return True # 3x3 체크 def ThreeXThree(x, y, val): nx = x//3 * 3 ny = y//3 * 3 for i in range(3): for j in range(3): if val == sudoku[nx+i][ny+j]: return False return True def DFS(index): if index == le..

[SWEA][D2] 1940. 가랏! RC카! (파이썬/Python)

#n초 동안 이동한 거리를 계산하는 프로그램 t = int(input()) for tc in range(1, t+1): n = int(input()) total = 0 speed = 0 for nc in range(n): a = list(map(int,input().split())) # 가속일 때 if a[0] == 1: speed += a[1] # 감속일 때 elif a[0] == 2: #현재 속도보다 감속할 속도가 더 큰 경우 속도는 0이 된다. if speed < a[1]: speed = 0 else: speed -= a[1] total += speed print(f"#{tc} {total}")

[백준][백트래킹] 15649. N과 M (1) (파이썬/Python)

#15649 from itertools import permutations n, m = map(int,input().split()) n_lst = [] for i in range(1, n+1): n_lst.append(i) for i in list(permutations(n_lst, m)): #1 permutations 함수를 통해서 n_lst에 저장된 값을 m개씩 출력하기 위함 for j in i: print(j, end =' ') #줄바꿈 없이 print() # permutations 함수를 통해 구현 한 방법 # 이때 tuple로 저장되기 때문에 list로 형변환해주어야 합니다. s = [1,2,3] 이라면 per = permutations(s, ..

[SWEA][D2] 1959. 두 개의 숫자열 (파이썬/Python)

t = int(input()) for tc in range(1, t+1) : n,m= map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) result = 0 if n == m: for i in range(n): result += a[i]*b[i] else: if n > m: c = n-m a = a[c:] for i in range(len(a)): result += a[i]*b[i] else: c = m-n b = b[c:] for i in range(len(b)): result += a[i]*b[i] print(f'#{tc} {result}') # 생각도 안하고 긴쪽 오른쪽에 맞춰..

[SWEA][D2] 1961. 숫자 배열 회전 (파이썬/Python)

t= int(input()) for tc in range(1, t+1): n = int(input()) lst = [input().split() for _ in range(n)] #90도 lst_90 = [] for i in range(n): tmp = [] for j in range(n): tmp.append(lst[j][i]) # 0,0 -> 0,1 -> 0,2 -> 1,0 -> 1,1 -> 1,2.... tmp.reverse() lst_90.append(tmp) #180도 lst_180 = [] for i in range(n): tmp = [] for j in range(n): tmp.append(lst_90[j][i]) #90도 돌린 것을 이용해서 tmp.reverse() lst_180.appen..