Algorithm/Implementation 40

[백준 20057번] 마법사 상어와 토네이도

20057번: 마법사 상어와 토네이도 마법사 상어가 토네이도를 배웠고, 오늘은 토네이도를 크기가 N×N인 격자로 나누어진 모래밭에서 연습하려고 한다. 위치 (r, c)는 격자의 r행 c열을 의미하고, A[r][c]는 (r, c)에 있는 모래의 양을 www.acmicpc.net n = int(input()) area = [list(map(int,input().split())) for _ in range(n)] dx = [0,1,0,-1] dy = [-1,0,1,0] count = 0 length = 1 direction = 0 answer = 0 x, y = n//2, n//2 def move(x,y,d): global answer total = area[x][y] five_percent = int(tot..

[백준 19236번] 청소년 상어

19236번: 청소년 상어 첫째 줄부터 4개의 줄에 각 칸의 들어있는 물고기의 정보가 1번 행부터 순서대로 주어진다. 물고기의 정보는 두 정수 ai, bi로 이루어져 있고, ai는 물고기의 번호, bi는 방향을 의미한다. 방향 bi는 www.acmicpc.net import copy def find_x_y(fish_number,area): # 물고기의 x,y 좌표를 찾는 함수 for i in range(4): for j in range(4): if area[i][j][0] == fish_number: return i,j def find_shark_loc(area): # 상어의 x,y 좌표를 찾는 함수 for i in range(4): for j in range(4): if area[i][j][0] == ..

[백준 17144번] 미세먼지 안녕!

17144번: 미세먼지 안녕! 미세먼지를 제거하기 위해 구사과는 공기청정기를 설치하려고 한다. 공기청정기의 성능을 테스트하기 위해 구사과는 집을 크기가 R×C인 격자판으로 나타냈고, 1×1 크기의 칸으로 나눴다. 구사 www.acmicpc.net import sys r, c, t = map(int, sys.stdin.readline().split()) area = [list(map(int, sys.stdin.readline().split())) for _ in range(r)] dx = [-1,1,0,0] dy = [0,0,-1,1] cleaner_list = [] answer = 0 for i in range(r): for j in range(c): if area[i][j] == -1: cleaner_..

[백준 15686번] 치킨 배달

15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net import itertools def calculate_distance(r1,c1,r2,c2): return abs(r1-r2) + abs(c1-c2) n, m = map(int,input().split()) input_city = [list(map(int,input().split())) for _ in range(n)] chicken_house_list = set() house_list = set() min_value = float("inf..

[백준 14890번] 경사로

https://www.acmicpc.net/problem/14890 n, l = map(int,input().split()) area = [list(map(int,input().split())) for _ in range(n)] total = 0 def checkLine(line): inclined = [False for _ in range(n)] for i in range(n-1): if line[i] == line[i+1]: # 높이가 같은 경우에는 Pass continue if abs(line[i]-line[i+1]) >= 2: # 낮은 칸과 높은 칸의 높이 차이가 1이 아닌 경우(조건 2) return False if line[i] > line[i+1]: # 내리막길인 경우 target = lin..

[백준 21610번] 마법사 상어와 비바라기

n,m = map(int,input().split()) area = [list(map(int,input().split())) for _ in range(n)] move_list = [] # 이동 정보 목록 for i in range(m): move_list.append(tuple(map(int,input().split()))) cloud_list= {(n-1,0), (n-1,1), (n-2,0), (n-2,1)} # 초기 구름 위치 dx = [0,-1, -1, -1, 0, 1, 1, 1] # 방향 x좌표 dy = [-1, -1, 0, 1, 1, 1, 0, -1] # 방향 y좌표 dx_2 = [-1,-1,1,1] # 대각선 이동을 위한 x좌표 dy_2 = [-1,1,-1,1] # 대각선 이동을 위한 y좌표..

[백준 14503번] 로봇 청소기

n,m = map(int,input().split()) r,c,d = map(int,input().split()) # 현재 방향을 기준으로 반시계방향으로 탐색 dx = [[0,1,0,-1],[-1,0,1,0],[0,-1,0,1],[1,0,-1,0]] dy = [[-1,0,1,0],[0,-1,0,1], [1,0,-1,0],[0,1,0,-1]] # 바라보는 방향이 북쪽인 경우 # dx_0 =[0,1,0,-1] # dy_0 =[-1,0,1,0] # 바라보는 방향이 동쪽인 경우 # dx_1 = [-1,0,1,0] # dy_1 = [0,-1,0,1] # 바라보는 방향이 남쪽인 경우 # dx_2 = [0,-1,0,1] # dy_2 = [1,0,-1,0] # 바라보는 방향이 서쪽인 경우 # dx_3 = [1,0,-1..

[백준 15662번] 톱니바퀴(2)

t = int(input()) gear = [[0]*8 for _ in range(t)] rotate_list = [] answer = 0 for i in range(t): gear[i] = list(map(int,list(input()))) def rotate_right(lst): # 시계 방향으로 회전시키는 함수 lst.insert(0,lst.pop()) def rotate_left(lst): # 반시계 방향으로 회전시키는 함수 lst.append(lst.pop(0)) k = int(input()) for i in range(k): # 회전 목록 입력받고 저장 number, direction = map(int,input().split()) rotate_list.append((number-1,direc..