[프로그래머스] 67256 파이썬 - 키패드 누르기
풀이키패드의 숫자와 각 숫자에 맞는 좌표를 미리 딕셔너리에 선언해두고 풀었다.나머지는 단순 구현이었다.if문을 사용해 조건만 잘 걸어주면 어렵지 않게 풀 수 있는 문제였다. 코드def solution(numbers, hand): answer = '' keypad = {'1':(0,0), '2':(0,1), '3':(0,2), '4':(1,0), '5':(1,1), '6':(1,2), '7':(2,0), '8':(2,1), '9':(2,2), '*':(3,0), '0':(3,1), '#':(3,2)} left = keypad['*'] right = keypad['#'] for number in numbers: ..
2024. 9. 5.
[백준] 18405번 파이썬 - 경쟁적 전염
문제 코드from collections import dequeimport sysinput = sys.stdin.readlinen,k = map(int,input().split())array = []virus = []# 배열 초기화for i in range(n): array.append(list(map(int,input().split()))) for j in range(n): if array[i][j] != 0: virus.append((array[i][j],0,i,j))virus.sort()queue = deque(virus)# s초 후에 (x,y) 위치에 바이러스 s,x,y = map(int,input().split())# 상하좌우dx = [0,0,-1,1]d..
2024. 8. 27.
[백준] 1095번 파이썬 - 마법의 구슬
s+f개의 구슬 중 s개를 뽑는 조합의 개수를 구하고그 개수를 m이하의 사람들에게 모두 같은 개수로 나누어 주면 되는데이 때 m의 값이 최대여야 한다.첫 번째 코드# 1,000,000,000범위 -> 시간복잡도 O(N)import maths,f,m = map(int,input().split())answer = -1# 1. s+f개로 만들 수 있는 조합의 개수 구하기 -> math.comb 시간복잡도 O(logn)combs = math.comb(s+f,s)# 2. m 이하의 사람들이 모두 같은 개수의 조합을 테스트 할 수 있도록 나누기if combs 시간초과 두 번째 코드# 1,000,000,000범위 -> 시간복잡도 O(N)import sysimport mathinput = sys.stdin.readl..
2024. 5. 10.