1. 처음 접근 방법 - permutations 함수 from itertools import permutations N = int(input()) input = tuple(map(int, input().split())) list_for_permutation = [i for i in range(1, N+1)] permutation = list(permutations(list_for_permutation, N)) if permutation[0] == input: print(-1) else: for i in range(1, len(permutation)): if permutation[i] == input: print(' '.join(list(map(str, permutation[i-1])))) 처음엔 pyth..
1. 백준 10157 C, R = map(int, input().split()) K = int(input()) board = [[0 for i in range(C)] for i in range(R)] if K > R*C: print(0) else: cnt = 1 direction = 0 dx = [-1, 0, 1, 0] # 상우하좌 dy = [0, 1, 0, -1] cr = R-1 cc = 0 while cnt = R or nc >= C or board[nr][nc] != 0: direction = (direction+1) % 4 # ..
from collections import deque from itertools import * # INPUT 받아오기 N, M = map(int, input().split()) houses = deque([]) chickens = deque([]) answer = 0 for y in range(N): inp = input().split() for x in range(N): if inp[x] == '1': houses.append((x, y)) if inp[x] == '2': chickens.append((x, y)) # 모든 집에서, 모든 치킨집까지의 거리 미리 계산하기 distances = deque([]) for house in houses: distance = [] #한 집에서 모든 치킨집까지의 ..
# 뱀의 위치를 Queue에 넣는 생각...! from collections import deque N = int(input()) K = int(input()) board = [[0] * N for _ in range(N)] dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] for _ in range(K): y, x = map(int, input().split()) board[y - 1][x - 1] = 1 L = int(input()) dirDict = dict() queue = deque([[0, 0]]) for i in range(L): r, c = input().split() dirDict[int(r)] = c x, y = 0, 0 board[y][x] = 2 cnt = 0 di..
1. 프로그래머스 42860 조이스틱 import re def getIdxMaxA(name): findAll = re.findall("A+", name) if not findAll: return len(name) - 1 regex = re.compile(max(findAll)) idx = regex.search(name).span() return idx def right_straight(arr): #오른쪽에서 A가 아닌 문자가 시작하는 위치 찾기 ans = 0 for ar in arr[::-1]: if ar == 0: ans += 1 else: break return len(arr) - ans def left_straight(arr): # 왼쪽에서 A가 아닌 문자가 시작하는 위치 찾기 ans = 0 fo..