Skip to content

Commit e66f8bf

Browse files
committed
2 parents abff64b + 45f5ce3 commit e66f8bf

File tree

9 files changed

+231
-0
lines changed

9 files changed

+231
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

syheo/.DS_Store

0 Bytes
Binary file not shown.

syheo/codingTest1/.DS_Store

0 Bytes
Binary file not shown.

syheo/codingTest1/Baekjoon/2178.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#solved.ac
2+
#실버1
3+
#DFS
4+
#미로 탈출
5+
#2178
6+
7+
#visited는 리스트이므로 mutable한 속성을 갖음 -> 깊은 복사가 필요
8+
import sys,copy
9+
input = sys.stdin.readline
10+
11+
N,M = map(int,input().split())
12+
13+
maps = []
14+
for i in range(N):
15+
maps.append(list(map(int,list(input().rstrip()))))
16+
17+
#dfs
18+
def dfs(maps,v):
19+
cntList = []
20+
visited=[[False]*M for _ in range(N)]
21+
stack = [(v[0],v[1],v[2],visited)]
22+
while stack:
23+
vertex = stack.pop()
24+
#예외 처리
25+
if vertex[0]>=0 and vertex[0]<N and vertex[1]>=0 and vertex[1]<M:
26+
cnt = vertex[2]
27+
row = vertex[0]
28+
col = vertex[1]
29+
visiting = copy.deepcopy(vertex[3])
30+
#방문 가능 여부 판별
31+
if not visiting[row][col] and maps[row][col]==1:
32+
if row == N-1 and col == M-1:
33+
cntList.append(cnt)
34+
#방문 처리
35+
else:
36+
visiting[row][col]=True
37+
stack.extend([(row+1,col,cnt+1,visiting),(row-1,col,cnt+1,visiting),(row,col+1,cnt+1,visiting),(row,col-1,cnt+1,visiting)])
38+
print(min(cntList))
39+
40+
41+
dfs(maps,(0,0,1))

syheo/codingTest1/Baekjoon/3061.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#solved.ac
2+
#실버4
3+
#그리디
4+
#사다리 타기
5+
#3061
6+
import sys
7+
input = sys.stdin.readline
8+
9+
cntList = []
10+
11+
#스왑 변형 병합 메서드
12+
def swap(array,x,cur,N):
13+
if cur<x:
14+
array = array[0:cur] + array[cur+1:x+1] + array[cur:cur+1]+ array[x+1:N+1]
15+
else:
16+
array = array[0:x] + array[cur:cur+1] + array[x:cur]+array[cur+1:N+1]
17+
return array
18+
19+
for i in range(int(input())):
20+
N = int(input())
21+
#도착점이 index , 시작점이 value
22+
arr = list(map(int,input().split()))
23+
arr.insert(0,0)
24+
#ladder = [0 for _ in range(N)]
25+
#카운트 변수
26+
cnt = 0
27+
#swapping 해서 1번~N번까지 위치를 찾아주며 오름차순 정렬
28+
for j in range(1,N+1):
29+
#cur이 j의 위치로 가야 되는 index 값 0 1 6 2 3 4 5 7
30+
cur = arr.index(j)
31+
if cur!=j:
32+
cnt+=abs(cur-j)
33+
arr =swap(arr,j,cur,N)
34+
#print(arr)
35+
cntList.append(cnt)
36+
#print(arr)
37+
38+
for i in cntList:
39+
print(i)
40+

syheo/codingTest1/Baekjoon/4963.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#solved.ac
2+
#실버2
3+
#BFS
4+
#섬의 개수
5+
#4963
6+
7+
#인접 행렬 방식으로 풀이
8+
9+
from collections import deque
10+
import sys
11+
input = sys.stdin.readline
12+
cntList = []
13+
while True:
14+
w,h = map(int,input().split()) #가로 세로
15+
if w ==0 and h==0:
16+
break
17+
#맵 생성
18+
maps=[[0]*(w+2)]
19+
for i in range(h):
20+
tmp=[0]+list(map(int,input().split()))+[0]
21+
maps.append(tmp)
22+
maps.append([0]*(w+2))
23+
#BFS
24+
visited = [[False]*(w+2) for _ in range(h+2)]
25+
q = deque([])
26+
cnt = 0
27+
for i in range(1,h+1):
28+
for j in range(1,w+1):
29+
if not visited[i][j] and maps[i][j]==1:
30+
q.append((i,j))
31+
visited[i][j]=True
32+
while q:
33+
v = q.popleft()
34+
for x in range(-1,2,1):
35+
for y in range(-1,2,1):
36+
vr = v[0]+x
37+
vc = v[1]+y
38+
if not visited[vr][vc] and maps[vr][vc]==1:
39+
q.append((vr,vc))
40+
visited[vr][vc]=True
41+
cnt+=1
42+
cntList.append(cnt)
43+
#출력
44+
for cnt in cntList:
45+
print(cnt)
46+
47+
48+
49+

syheo/codingTest1/scofe2/1.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
import sys
3+
input = sys.stdin.readline
4+
5+
N, time = map(str,input().split())
6+
N = int(N)
7+
h = int(time[0:2])
8+
m = int(time[3:5])
9+
s = int(time[6:8])
10+
times = h*60*60+ m*60 + s
11+
12+
timeList = [0 for _ in range(N)]
13+
dp= [0 for _ in range(N+1)]
14+
15+
maxSongIdx= -1
16+
maxSong=-1
17+
#플레이리스트 입력
18+
for i in range(N):
19+
tmp = input()
20+
timeList[i]=int(tmp[0:2])*60+int(tmp[3:5])
21+
22+
start = 0
23+
sum = 0
24+
cnt = 0
25+
for i in range(N):
26+
sum+=timeList[i]
27+
cnt+=1
28+
if sum >=times:
29+
if maxSong<cnt:
30+
maxSong = cnt
31+
maxSongIdx = start
32+
while sum>=times:
33+
sum-=timeList[start]
34+
start+=1
35+
cnt -= 1
36+
37+
38+
print(maxSong,maxSongIdx+1,end=' ')

syheo/codingTest1/scofe2/2.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
sys.setrecursionlimit(10**7)
3+
input = sys.stdin.readline
4+
5+
N = int(input())
6+
7+
def find_path(last,visited):
8+
if visited == (1<<n)-1:
9+
return info[country[last]][0] or INF
10+
if DP[last][visited] is not None:
11+
return DP[last][visited]
12+
tmp=INF
13+
for city in range(n):
14+
if visited & (1 << city) == 0 and info[country[last]][city] != 0:
15+
tmp=min(tmp,find_path(city,visited|(1<<city)) + info[country[last]][city])
16+
DP[last][visited]=tmp
17+
return tmp
18+
19+
country = []
20+
info = dict()
21+
INF = int(10000)
22+
23+
for i in range(N):
24+
c1, c2,cost = map(str,input().split())
25+
if c1 not in info.keys():
26+
country.append(c1)
27+
info[c1]=[0 for _ in range(6)]
28+
if c2 not in info.keys():
29+
country.append(c2)
30+
info[c2]=[0 for _ in range(6)]
31+
info[c1][country.index(c2)]=int(cost)
32+
info[c2][country.index(c1)]=int(cost)
33+
n = len(country)
34+
35+
DP=[[None]*(1<<n) for _ in range(n)]
36+
37+
38+
print(find_path(0,1<<0))
39+
40+
41+
42+
43+

syheo/codingTest1/scofe2/4.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
3+
N = int(input())
4+
indexList = []
5+
for i in range(N):
6+
indexList.append(input())
7+
Q = int(input())
8+
9+
for i in range(Q):
10+
tmp = input()
11+
cnt = 0
12+
r = re.compile('.(%s).'%tmp)
13+
tmpList = list(filter(r.match, indexList))
14+
print(tmpList)
15+
for j in indexList:
16+
match = re.findall(re.escape(tmp), j)
17+
#print('match',match)
18+
cnt+=len(match)
19+
#print(cnt)
20+

0 commit comments

Comments
 (0)