Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- vuejs
- cos pro
- 파이썬
- DFS와BFS
- 안드로이드스튜디오
- 백준
- 코딩테스트
- django
- 개발
- cos
- 분할정복
- cos pro 1급
- 코테
- issue
- k8s
- Flutter
- 코드품앗이
- AndroidStudio
- 동적계획법
- C++
- 안드로이드
- codingtest
- android
- 동적계획법과최단거리역추적
- BAEKJOON
- Algorithm
- 알고리즘
- DFS
- Python
- DART
Archives
- Today
- Total
Development Artist
[COS Pro 1급, Python] 1차 6번 : 체스의 나이트 본문
728x90
문제 유형
코딩
난이도 (주관적인)
easy
Note
1. dx, dy로 나이트의 이동 경우를 고정하기. bfs에서 자주 쓰이는 방식인데, 원할한 순회를 위해 이런식으로 이동 값을 설정.
Code
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
var_N = 8
dx = [1, 2, 2, 1, -1, -2, -2, -1]
dy = [-2, -1, 1, 2, 2, 1, -1, -2]
def solution(pos):
answer = 0
start_row = int(pos[1])
start_col = ord(pos[0])-65
for i in range(var_N):
now_row = start_row + dx[i]
now_col = start_col + dy[i]
if now_row in range(0,9) and now_col in range(0,9):
answer += 1
return answer
pos = 'A7'
ret = solution(pos)
print("solution 함수의 반환 값은", ret, "입니다.")
※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.
728x90
'Algorithm > COS' 카테고리의 다른 글
[COS Pro 1급, Python] 1차 8번 : 누가 당선 되나요 (1) | 2022.02.24 |
---|---|
[COS Pro 1급, Python] 1차 7번 : 병합 and 정렬 (0) | 2022.02.24 |
[COS Pro 1급, Python] 1차 5번 : 소용돌이 수 (0) | 2022.02.24 |
[COS Pro 1급, Python] 1차 4번 : 타임머신 (0) | 2022.02.24 |
[COS Pro 1급, Python] 1차 3번 : 계산기 by 문자열 (0) | 2022.02.24 |
Comments