티스토리 뷰
구현 : 머릿속의 알고리즘을 소스코드로 바꾸는 과정
*언어중 구현이 가장 쉽지만 시간이 길게 걸리는 python. c로 짤 수 있지만 python 코딩테스트 준비를 위해 python으로 작성할 예정
*사용할 언어 : python => int자료형의 데이터 개수에 따른 메모리 사용량을 고려해야한다.
list길이(데이터 개수) | 메모리 사용량 |
1,000(천) | 약 4KB |
1,000,000(백만) | 약 4MB |
10,000,000(천만) | 약 40MB |
참고해서 개발환경에 따라 list사용여부, 활용 방법 등을 생각해내야함.
#구현
#상하좌우 => 좌표를 list로 만들어 넣고 x좌표가 1보다 작으면 안 되고 n을 넘을때부터 안 됨. y도 마찬가지로 생각. 나머지는 그냥 for문과 if로 간단히 처리
'''
n = int(input())
x=1
y=1
list = list(input())
for i in range(0,len(list)):
if list[i]=='R' and y<n:
y+=1
if list[i]=='U' and x>1:
x-=1
if list[i] == 'L' and y>1:
y-=1
if list[i] == 'D' and x<n:
x+=1
print(x,y)
'''
#시각 => 문자열에 3이 하나라도 포함되면 count
'''
n = str(input())
count=0
for i in range(0,int(n)+1):
for j in range(0,60):
for h in range(0,60):
if n in str(i) + str(j) + str(h):
count+=1
print(count)
'''
#왕실의 나이트 => 이동할 수 있는 경우의 수 구하는 문제 -> 경계값을 좌료로 조절하는 코드
'''
nite=input()
x_list=['a','b','c','d','e','f','g','h']
for i in range(0,len(x_list)):
if nite[0]==x_list[i]:
x = i+1
y = int(nite[1])
#수평으로 이동할 4가지 경우고려
count=0
if x>=3:
if y<2:
count+=1
if y>7:
count+=1
else:
count+=2
if x<=6:
if y<2:
count+=1
if y>7:
count+=1
else:
count+=2
#수직으로 이동할 4가지 경우 고려
if y>=3:
if x<2:
count+=1
if x>7:
count+=1
else:
count+=2
if y<=6:
if x<2:
count+=1
if y>7:
count+=1
else:
count+=2
print(8-count)
'''
#게임개발 =>사방으로 1인 경우에 뒤로 가는데 뒤가 바다일때 stop
'''
n,m= map(int,input().split())
x,y,d = map(int,input().split())
list_=[0]*n
for i in range(0,n):
z = list(map(int,input().split()))
list_[i]=z
count=0
print(list_)
while(True):
list_[y][x]=2
count+=1
if d==0:
if y-1>=0 and list_[y-1][x]==0:
d=3
y=y-1
elif x+1<= n-1 and list_[y][x+1]==0:
d=2
x=x+1
elif y+1<=m-1 and list_[y+1][x]==0:
d=1
y=y+1
elif y-1<=0 and list_[y-1][x]==0:
d=0
y=y-1
else:
if list_[y][x+1]==2:
x=x+1
else:
break
elif d==1:
if x-1<=0 and list_[y][x-1]==0:
x=x-1
d=0
elif y-1>=0 and list_[y-1][x]==0:
d=3
y=y-1
elif x+1<= n-1 and list_[y][x+1]==0:
d=2
y=y+1
elif y+1<=m-1 and list_[y+1][x]==0:
d=1
y=y+1
else:
if list_[y-1][x]==2:
y=y-1
else:
break
elif d==2:
if y+1<=m-1 and list_[y+1][x]==0:
d=1
y=y+1
elif x-1<=0 and list_[y][x-1]==0:
x=x-1
d=0
elif y-1>=0 and list_[y-1][x]==0:
d=3
y=y-1
elif x+1<= n-1 and list_[y][x+1]==0:
d=2
y=y+1
else:
if list_[y][x-1]==2:
x=x-1
else:
break
else:
if x+1<= n-1 and list_[y][x+1]==0:
d=2
y=y+1
elif y+1<=m-1 and list_[y+1][x]==0:
d=1
y=y+1
elif x-1<=0 and list_[y][x-1]==0:
x=x-1
d=0
elif y-1>=0 and list_[y-1][x]==0:
d=3
y=y-1
else:
if list_[y+1][x]==2:
y=y+1
else:
break
print(count)
'''
'파이썬 > 파이썬 기초' 카테고리의 다른 글
정렬 (0) | 2021.08.06 |
---|---|
dfs와 bfs (0) | 2021.08.01 |
그리디 알고리즘 (0) | 2021.07.16 |
리스트를 다루는 map()과 filter() - lambda (0) | 2021.03.28 |
파이썬 기초 - 알아두면 유용 (0) | 2021.03.24 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- c++덱
- CSMA/CD란?
- 파이썬 알아두면 유용
- 백준 11053 파이썬
- 4963 섬의개수
- 효율적인방법찾기
- 13886
- 백트래킹(1)
- CREATE ASSERTION
- 코딩월드뉴스
- stack 컨테이너
- DRF 회원관리
- 시뮬레이션 c
- 기본 텍스트 분류
- 온라인프로필 만들기
- 10866 백준
- 백준 4963
- LAMBDA
- 백준 15650 파이썬
- 백준 숫자놀이
- 기사작성 대외활동
- 모듈 사용법
- 스택 파이썬
- 백준 10866
- 핀테크 트렌드
- 11053 백준
- 영화 리뷰 긍정 부정 분류
- mm1queue
- 딥러닝입문
- 소프트웨어공학설계
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함