Skip to content

Commit 33d84ae

Browse files
committed
upload files
1 parent c1ee370 commit 33d84ae

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

week14/Junbeom/로봇청소기.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 방향 변경 + dfs
2+
import sys
3+
from collections import deque
4+
5+
n, m = map(int, input().split())
6+
7+
dx = [-1, 0, 1, 0] # 0 1 2 3 상 우 하 좌
8+
dy = [0, 1, 0, -1]
9+
10+
r, c, d = map(int, input().split())
11+
12+
graph = []
13+
for _ in range(n):
14+
graph.append(list(map(int, input().split())))
15+
ans = 0
16+
17+
def clean(x, y, d):
18+
global ans
19+
if graph[x][y] == 0:
20+
graph[x][y] = 2
21+
ans += 1
22+
for _ in range(4):
23+
nd = (d + 3) % 4
24+
nx = x + dx[nd]
25+
ny = y + dy[nd]
26+
if graph[nx][ny] == 0: # 청소할 곳이 생기면
27+
clean(nx, ny, nd)
28+
return
29+
d = nd # 왼 방향으로 회전
30+
nd = (d + 2) % 4 # 네 방향이 갈 수 없는 상태면 뒤로 이동 (d+2)
31+
nx = x + dx[nd]
32+
ny = y + dy[nd]
33+
if graph[nx][ny] == 1: # 그럼에도 청소할 곳이 더 없으면
34+
return # 종료
35+
clean(nx, ny, d)
36+
37+
clean(r, c, d)
38+
print(ans)

week14/Junbeom/문자열폭발.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 못 풀어서 디른 분의 풀이 참고함.
2+
# 기본 아이디어 : 입력 문자열에 하나씩 값을 담아, 스택에 푸쉬함. 그 다음 현재 문자가 폭탄의 마지막 글자와 같은지, 그리고 길이가 같은지를 판단하고 pop함.(삭제)
3+
import sys
4+
input = sys.stdin.readline
5+
6+
s = input().rstrip()
7+
bomb = input().rstrip()
8+
9+
last = bomb[-1]
10+
stack = []
11+
l = len(bomb)
12+
13+
for ch in s:
14+
stack.append(ch)
15+
if ch == last and ''.join(stack[-l:]) == bomb:
16+
del stack[-l:]
17+
18+
answer = ''.join(stack)
19+
20+
if answer == '':
21+
print("FRULA")
22+
else:
23+
print(answer)
24+
25+

week14/Junbeom/뱀.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 3190 뱀
2+
# idea : 1. 자신에 부딪히면 안되므로 뱀을 2로 부여해서 조건을 넣는다. 2. 시간이 되면 방향을 바꿔주어야 하는데 방향벡터로 시계방향 반시계방향을 만들어 놓는다. 3. 덱으로 뱀의 길이조절을 한다.
3+
import sys
4+
from collections import deque
5+
6+
7+
# index - 0: 북, 1: 동, 2: 남, 3: 서
8+
dy = [-1, 0, 1, 0]
9+
dx = [0, 1, 0, -1]
10+
11+
12+
N = int(sys.stdin.readline())
13+
K = int(sys.stdin.readline())
14+
board = [[0] * N for _ in range(N)]
15+
for _ in range(K):
16+
a, b = map(int, sys.stdin.readline().split())
17+
board[a-1][b-1] = 1 # 사과 1로 저장
18+
19+
L = int(sys.stdin.readline())
20+
21+
times = {} # dictionary
22+
23+
for i in range(L):
24+
X, C = sys.stdin.readline().split()
25+
times[int(X)] = C
26+
27+
dir = 1 # 초기의 방향 - default
28+
time = 1 # 시간
29+
y = x = 0
30+
snake = deque([[y, x]]) # 방문 위치
31+
board[y][x] = 2 # 뱀은 2로 표시
32+
33+
while True:
34+
y, x = y + dy[dir], x + dx[dir]
35+
if 0 <= y < N and 0 <= x < N and board[y][x] != 2: # 보드 안에 있거나, 자신을 만나지 않는 경우
36+
if board[y][x] == 0: # 사과가 없는 경우
37+
tail_y, tail_x = snake.popleft() # 꼬리를 미리 떼서 뱀 크기 유지
38+
board[tail_y][tail_x] = 0 # 꼬리 제거
39+
40+
board[y][x] = 2 # 진행방향은 뱀으로 바꿈
41+
snake.append([y, x]) # 늘려줌.
42+
if time in times.keys(): # 방향을 바뀔 시간이 되면,
43+
if times[time] == "D" : # Default일 때
44+
dir = (dir+1) % 4 # overflow 방지해서 modulo 사용
45+
else: # Left일 때
46+
dir = (dir+3) % 4
47+
48+
time += 1
49+
else: # 본인 몸에 부딪히거나, 벽에 부딪힌 경우 종료.
50+
print(time)
51+
exit(0)
52+
53+
54+
55+
56+

0 commit comments

Comments
 (0)