반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 컴퓨터 비전
- 인공지능
- 로지스틱 회귀
- neural network
- pre-trained
- recommender system
- Regularization
- 컴퓨터 그래픽스
- Support Vector Machine
- Kaggle
- logistic regression
- 비용함수
- cs231n
- C++
- 머신러닝
- SGD
- 그래픽스
- 신경망
- petal to metal
- CNN
- 백준
- 추천 시스템
- SVM
- Unsupervised learning
- Computer Vision
- Vision
- OpenGL
- 파이썬
- 딥러닝
- CPP
Archives
- Today
- Total
kwan's note
백준 3190 번 뱀 파이썬 (python code) 본문
반응형
3190번: 뱀
'Dummy' 라는 도스게임이 있다. 이 게임에는 뱀이 나와서 기어다니는데, 사과를 먹으면 뱀 길이가 늘어난다. 뱀이 이리저리 기어다니다가 벽 또는 자기자신의 몸과 부딪히면 게임이 끝난다. 게임
www.acmicpc.net
간단한 구현문제이다.
시간이 좀 걸리긴했는데 문제만 잘 읽고 따라푼다면 충분히 풀만한 문제인듯하다.
고려할것은
1.뱀의 머리방향을 어떻게 돌릴지
2.break 타이밍
정도가 될것같다.
뱀의 머리방향을 동, 북, 서, 남 순서로 놓고 왼쪽을 보려면 +1 오른쪽을 보려면 -1하였다.
그리고 뱀은 자라는게 먼저이므로 자라자 마자 break를 해야한다.
N = int(input())
K = int(input())
appl = [list(map(int,input().split())) for _ in range(K)]
L = int(input())
Ldir=[0]*L
Ltime=[0]*L
for i in range (L):
Ltime[i],Ldir[i] = input().split()
snake = [[1, 1]]
face = [[0, 1], [-1, 0], [0, -1], [1, 0]]
sface = 0
time =0
while(True):
time+=1
new_face= [snake[0][0]+face[sface][0],snake[0][1]+face[sface][1]]
snake.insert(0, new_face)
if snake[0][0] > N or snake[0][1] > N or snake[0][0] < 1 or snake[0][1] < 1 :
break
if snake[0] in snake[1:]:
break
if (snake[0] in appl):
appl.remove(snake[0])
else:
snake.pop()
if Ltime:
if time == int(Ltime[0]):
if Ldir[0]=='D':
sface= 3 if sface==0 else sface-1
elif Ldir[0] =='L':
sface= 0 if sface ==3 else sface+1
else:
print("dir error")
del Ltime[0]
del Ldir[0]
print(time)
반응형
'Algorithm > python' 카테고리의 다른 글
백준 - 14889번: 스타트와 링크 파이썬 (0) | 2021.04.26 |
---|---|
순열과 조합 (0) | 2021.04.25 |
백준 2217번 로프 파이썬 (python code) (0) | 2021.01.21 |
백준 11758번 CCW 파이썬 (python code) (0) | 2021.01.17 |
백준 1010번 다리놓기 파이썬 (python code) (1) | 2021.01.17 |