모든 경우의 수를 주저 없이 다 계산하는 해결 방법
-> 비효율적인 시간 복잡도를 가지고 있으므로 데이터 개수가 큰 경우에 정상적으로 작동x
문제에서 제시한 알고리즘을 한 단계씩 차례대로 직접 수행
#5
# R R R U D D
n = int(input())
x , y = 1, 1 #초기값 세팅
plans = input.split()
dx = [0, 0, -1, 1]
dy = [-1, 1,0, 0]
move_types = ['L', 'R', 'U', 'D']
for plan in plans:
for i in range(len(move_types)):
if plan == move_types[i]:
nx = x + dx[i]
ny = y + dy[i]
if nx > n or ny > n or ny < 1 or nx < 1:
continue
x , y = nx, ny
print(x,y)
h = int(input())
count = 0
for i in range(h+1):
for j in range(60):
for k in range(60):
if '3' in str(i) + str(j) + str(k):
count += 1
print(count)
input_data= input() #a1
row = int(input_data[1]) #뒷자리 숫자
column = int(ord(input_data[0])- ord("a")) + 1
# 입력되는 알파벳의 자리값 - 기본 알파벳 자리값 + 1 (1부터 시작이니까 더하기 1)
result = 0
#좌표의 이동 가능한 방향 정의
steps = [(-2,1),(-2,-1),(2,1),(2,-1),(-1,2),(-1,-2),(1,2),(1,-2)]
for step in steps:
next_row = row + step[0]
next_column = column + step[1]
#좌표의 범위를 벗어나지 않는다면
if next_row >=1 and next_row <=8 and next_column >=1 and
next_column <=8:
result +=1
print(result)
ord(c)는 문자의 유니코드 숫자 값을 리턴하는 함수
ord 함수는 chr 함수와 반대
>>> ord('a')
97
>>> ord('가')
44032
파이썬에서 언더스코어(_)는 특별한 의미
# N X M 크기의 2차원 리스트 초기화
>>> m = 5
>>> n = 8
>>> array = [[0]*m for _ in range(n)]
>>> array
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ... , [0, 0, 0, 0, 0]]
이건,, 문제가 도저히 이해가 안간다...