Skip to content

Commit 40c913a

Browse files
authored
승연 백준 숙제 (4/20/화) (#65)
* 2437 * 1600 * 주석 담
1 parent f17ef27 commit 40c913a

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

syheo/codingTest1/Baekjoon/1600.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#solved.ac
2+
#골드5
3+
#dfs
4+
#말이 되고 싶은 원숭이
5+
#1600
6+
7+
8+
import sys
9+
from collections import deque
10+
input = sys.stdin.readline
11+
12+
horseMove = [(-1,-2),(-2,-1),(-1,2),(-2,1),(1,2),(2,1),(1,-2),(2,-1)]
13+
kingkongMove = [(-1,0),(1,0),(0,1),(0,-1)]
14+
15+
K = int(input())
16+
W,H = map(int,input().split())
17+
visited = [[[False for _ in range(31)] for j in range(W)] for i in range(H)]
18+
19+
maps = []
20+
#맵 입력
21+
for i in range(H):
22+
maps.append(list(map(int,input().split())))
23+
24+
#정답 체크 함수
25+
def check_ans(r,c):
26+
if r==H-1 and c==W-1:
27+
return True
28+
else:
29+
return False
30+
31+
#bfs 시작
32+
q = [(0,0,K,0)] #시작 지점 좌표,K의 갯수(남은 갯수),이동거리수
33+
q = deque(q)
34+
35+
def bfs():
36+
while q:
37+
row,col,k,cnt = q.popleft()
38+
#도착가능 확인
39+
if check_ans(row,col):
40+
return cnt
41+
#원숭이의 이동으로 갈 때
42+
for move in kingkongMove:
43+
r=row+move[0]
44+
c=col+move[1]
45+
if 0<=r<=H-1 and 0<=c<=W-1 and not visited[r][c][k] and maps[r][c]==0:
46+
visited[r][c][k]=True
47+
q.append((r,c,k,cnt+1))
48+
49+
#말의 이동으로 갈 수 있을 떄
50+
if k>0:
51+
for move in horseMove:
52+
r=row+move[0]
53+
c=col+move[1]
54+
if 0<=r<=H-1 and 0<=c<=W-1 and not visited[r][c][k-1] and maps[r][c]==0:
55+
visited[r][c][k-1]=True
56+
q.append((r,c,k-1,cnt+1))
57+
58+
return -1
59+
60+
print(bfs())

syheo/codingTest1/Baekjoon/2437.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#solved.ac
2+
#골드3
3+
#그리디
4+
#저울
5+
#2437
6+
import sys
7+
input = sys.stdin.readline
8+
9+
#아이디어
10+
#ans ==> 현재까지 측정 가능한 물건의 최대 무게
11+
#ans + 1 ==> 현재로 측정할 수 없는 최소 무게
12+
#ans + chu ==> 만약 ans가 chu보다 크거나 같으면 ans 를 현재 추의 무게까지 더하여 갱신.
13+
14+
N = int(input())
15+
ans = 1
16+
chuList = list(map(int,input().split()))
17+
chuList.sort()
18+
for chu in chuList:
19+
if ans<chu:
20+
break
21+
ans+=chu
22+
print(ans)
23+

0 commit comments

Comments
 (0)