[백준 바킹독] 0x09 - BFS 토마토(7576)
Introduction
https://www.acmicpc.net/problem/14503
def robot_clean(locations,robot_loc):
locations[robot_loc[0]][robot_loc[1]] = 2
return locations
def check_clean(locations,robot_loc,robot_pos):
# search
if robot_pos == 0:
loc = locations[robot_loc[0]-1][robot_loc[1]]
elif robot_pos == 1:
loc = locations[robot_loc[0]][robot_loc[1]+1]
elif robot_pos == 2:
loc = locations[robot_loc[0]+1][robot_loc[1]]
elif robot_pos == 3:
loc = locations[robot_loc[0]][robot_loc[1]-1]
# check
if loc == 0: res = True
else: res = False
return res
def robot_go(robot_loc,robot_pos):
if robot_pos == 0: robot_loc[0] -= 1
elif robot_pos == 1: robot_loc[1] += 1
elif robot_pos == 2: robot_loc[0] += 1
elif robot_pos == 3: robot_loc[1] -= 1
return robot_loc
def robot_left(robot_pos):
if robot_pos == 0: robot_pos = 3
elif robot_pos == 1: robot_pos = 0
elif robot_pos == 2: robot_pos = 1
elif robot_pos == 3: robot_pos = 2
return robot_pos
def robot_back(robot_loc,robot_pos):
if robot_pos == 0: robot_loc[0] += 1
elif robot_pos == 1: robot_loc[1] -= 1
elif robot_pos == 2: robot_loc[0] -= 1
elif robot_pos == 3: robot_loc[1] += 1
return robot_loc
def print_location(locations):
for i in range(len(locations)):
print(locations[i])
N, M = map(int,input().split())
r, c, d = map(int,input().split())
locations = []
for _ in range(N):
loc = list(map(int,input().split()))
locations.append(loc)
#print("-- location --")
#print_location(locations)
# (r,c), (x,y)
# d==0 왼쪽, d==1 아래, d==2 오른쪽, d==3 위
robot_loc = [r,c]
robot_pos = d
result = 0
do = True
while(do):
locations = robot_clean(locations,robot_loc)
result += 1
#print("-- state{} --".format(result))
#print_location(locations)
cnt = 0
flag = True
while(flag):
cnt += 1
robot_pos = robot_left(robot_pos)
check = check_clean(locations,robot_loc,robot_pos)
if check == True:
#print("--- step 1: go ---")
robot_loc = robot_go(robot_loc,robot_pos)
flag = False
elif check == False and cnt<4:
#print("--- step 2: left ---")
pass
elif check == False and cnt==4:
#print("--- step 3: back ---")
robot_loc = robot_back(robot_loc,robot_pos)
cnt = 0
if locations[robot_loc[0]][robot_loc[1]] == 1:
#print("--- stop ---")
flag = False
do = False
#if result == 100:
# flag = False
# do = False
print(result)
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
1167 트리의 지름
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Git 명령어를 사용한 하위 디렉토리 다운로드 Clone 할 로컬 저장소 생성
Introduction
# Fetch the submodule commits into the main repository git remote add submodule_origin git://url/to/submodule/origin git fetch submodule_origin
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Graph
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Introduction
Spring Project
the page for java
가벼운 Base image를 사용
version: 3.0.0a10
WIDTH
version: 3.0.0a10
#include <iostream> #include <thread> #include <chrono> #include <mutex> #include <atomic> #include <string.h>
version: 3.0.0a10
https://cplusplus.com/reference/future/
Multithreading support was introduced in C++11.
how to costom github blog using jekyll
You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different wa...