[백준] 2583 파이썬 - 영역 구하기
문제https://www.acmicpc.net/problem/2583 풀이입력에 따라 직사각형을 입력받고,bfs를 통해 영역을 판별하여 넓이를 구하면 되는 문제이다. 입력을 받을 때, 모눈종이의 왼쪽 아래 꼭짓점의 좌표가 (0,0)으로 선언되어있어 약간 헷갈렸으나우리가 아는 대로(왼쪽 위가 (0,0)좌표) 코드를 작성해도 답을 도출하는 데에는 전혀 문제가 없다. 코드from collections import dequerow, column, k = map(int,input().split())matrix = [[1 for _ in range(column)] for _ in range(row)]for _ in range(k): lx,ly,rx,ry = map(int,input().split()) f..
2024. 9. 9.
[프로그래머스] 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.