Skip to content

Commit 92da647

Browse files
authored
Merge pull request #190 from AlgorithmStudy-Allumbus/hongjoo
Hongjoo / 4์›” 2์ฃผ์ฐจ / 6๊ฐœ
2 parents 743981a + a83c69b commit 92da647

11 files changed

+724
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
์‹ค๋ฒ„3
3+
https://www.acmicpc.net/problem/1783
4+
5+
#๋ฌธ์ œ : ๊ทธ๋ž˜ํ”„ํƒ์ƒ‰(DFS , BFS)
6+
- NxM ์˜ ์™ผ์ชฝ ์•„๋ž˜ ์นธ ์‹œ์ž‘
7+
- 4๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์ด๋™
8+
(1) 2์นธ ์œ„ , 1์นธ ์˜ค๋ฅธ์ชฝ
9+
(2) 1์นธ ์œ„๋กœ 2์นธ ์˜ค๋ฅธ์ชฝ
10+
(3) 1์นธ ์•„๋ž˜๋กœ , 2์นธ ์˜ค๋ฅธ์ชฝ
11+
(4) 2์นธ ์•„๋ž˜ , 1์นธ ์˜ค๋Аใ…œใ„น์ชฝ
12+
- goal) ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ๋Š” "์ตœ๋Œ€ ์นธ ๊ฐœ์ˆ˜" ๊ตฌํ•˜๊ธฐ
13+
14+
# ์กฐ๊ฑด
15+
- <์ด๋™ํšŸ์ˆ˜๊ฐ€ 4๋ฒˆ ์ด์ƒ -> ์ด๋™ ๋ฐฉ๋ฒ• ๋ชจ๋‘ ์‚ฌ์šฉ
16+
- < 4๋ฒˆ ์ดํ•˜ - ์ œ์•ฝ ์—†์Œ
17+
18+
19+
"""
20+
n, m = map(int, input().split())
21+
22+
result = 0
23+
# n์ด 1์ผ ๋•Œ ๋ฌด์กฐ๊ฑด 1
24+
if n == 1:
25+
result = 1
26+
# n์ด 2์ผ ๋•Œ
27+
elif n == 2:
28+
if m >= 1 and m <= 6: #m์ด 1~6์ผ ๋•Œ
29+
result = (m + 1) // 2
30+
elif m >= 7: #7์ด์ƒ์ผ ๋•Œ
31+
result = 4
32+
# n์ด 3 ์ด์ƒ์ผ ๋•Œ
33+
elif n >= 3:
34+
if m <= 6: #m์ด 1~6์ผ ๋•Œ
35+
result = min(m, 4)
36+
elif m >= 7: #m์ด 7 ์ด์ƒ์ผ ๋•Œ
37+
result = m - 2
38+
print(result)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
https://www.acmicpc.net/problem/10844
3+
"""
4+
n = int(input())
5+
# dp [์ด ๊ธธ์ด i ][๋งˆ์ง€๋ง‰ ์ž๋ฆฌ์ˆ˜๊ฐ€ j] = ์ธ ๊ฐœ์ˆ˜
6+
Mod = 1000000000
7+
# 1. ์ดˆ๊ธฐํ™”
8+
#(1) 0์„ ์‹œ์ž‘ํ•˜๋Š” ์ˆ˜๋Š” ๊ณ„๋‹จ์ˆ˜๊ฐ€ ์•„๋‹Œ๋‹ค - dp[1][0]
9+
# (2) N=1 ์ธ ๊ณ„๋‹จ์ˆ˜
10+
dp = [[0]*10 for _ in range(n+1)]
11+
dp[1][0] = 0
12+
for j in range(1,10):
13+
dp[1][j]= 1
14+
15+
# (3) ์ ํ™”์‹ N>=2
16+
for i in range(2,n+1):
17+
for j in range(10):
18+
if j== 0 :
19+
dp[i][j] = dp[i-1][j+1]
20+
elif j==9:
21+
dp[i][j] = dp[i-1][j-1]
22+
else :
23+
dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1]
24+
25+
print(sum(dp[n])%Mod)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
https://www.acmicpc.net/problem/2437
3+
4+
# ๋ฌธ์ œ
5+
- ์ €์šธ N๊ฐœ์˜ ์กฐํ•ฉ์˜ ํ•ฉ์œผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์—†๋Š” ์–‘์˜ ์ตœ์†Œ๊ฐ’ ๊ตฌํ•˜๊ธฐ
6+
- N<=1000๊ฐœ
7+
- 1๊ฐœ ๋ฌด๊ฒŒ >= 1,000,0000
8+
์œ ํ˜• : ๊ทธ๋ฆฌ๋”” , ์ •๋ ฌ
9+
10+
"""
11+
#1. ์ž…๋ ฅ ์ €์šธ์ถ” & ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
12+
N = int(input())
13+
weights = sorted(list(map(int, input().split())))
14+
target = 1
15+
for w in weights :
16+
if target < w :
17+
break
18+
19+
target += w
20+
print(target)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
https://www.acmicpc.net/problem/9996
3+
"""
4+
N = int(input())
5+
# Q. a*b๋Š” asbasd๋„ ์ •๋‹ต์ธ๊ฐ€?
6+
# 1. ๋ณ€์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ
7+
pattern = list(input().split('*'))
8+
cmstr = [[] for k in range(N)]
9+
10+
for i in range(N):
11+
# cmstr[i] = [x for x in input()]
12+
cmstr[i] = input()
13+
#2.
14+
15+
for i in range(N):
16+
# ํŒจํ„ด ์•ž, ๋’ค ๋งค์นญํ•˜๊ธฐ
17+
if cmstr[i][:len(pattern[0])] != pattern[0] or cmstr[i][-len(pattern[-1]):] != pattern[-1]:
18+
print("NE")
19+
continue
20+
# ์•ˆ ๋งž์Œ
21+
22+
flag = [False * len(pattern[1:-1])]
23+
point = len(pattern[0])
24+
for p in pattern[1:-1] : # ํŒจํ„ด ๋‚ด๋ถ€
25+
cnt = cmstr[i][point:].find(p)
26+
if cnt < 0 : #์—†์œผ๋ฉด
27+
print("NE")
28+
break
29+
# ์žˆ์œผ๋ฉด - ๊ทธ ์ด์ „์— ์žˆ์Œ
30+
point = cnt
31+
32+
print("DA")
33+
34+
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
"""
2+
#2024์‚ผ์„ฑ ์ƒ๋ฐ˜๊ธฐ ์˜ค์ „1๋ฒˆ ๋ฌธ์ œ / ๊ณ ๋Œ€๋ฌธ๋ช…์œ ์ ํƒ์‚ฌ
3+
#๋งํฌ : https://www.codetree.ai/ko/frequent-problems/problems/ancient-ruin-exploration/description?introductionSetId=&bookmarkId=
4+
5+
6+
"""
7+
"""
8+
# ์œ ํ˜• : ๊ฑ ๊ตฌํ˜„
9+
- . 5x5์œ„ 7๊ฐ€์ง€ ์œ ๋ฌผ(1-7)
10+
1. ํƒ์‚ฌ ์ง„ํ–‰ - ์ง€์ •๋œ 3x3ํšŒ์ „ ์‹œ๊ณ„๋ฐฉํ–ฅ์œผ๋กœ [90,180 , 270] ์ค‘ ํ•˜๋‚˜์˜ ๊ฐ๋„๋กœ ํšŒ์ „
11+
=> ๊ฐ ํšŒ์ „์‹œ "๊ฐ๋„| ํš๋“๊ฐ€์น˜ | ์ค‘์‹ฌ์ขŒํ‘œ" ์ €์žฅ
12+
- (1) ์œ ๋ฌผ 1์ฐจ ํš๋“ ๊ฐ€์น˜ ์ตœ๋Œ€ํ™”
13+
- (2) ํšŒ์ „ ๊ฐ๋„ ์ตœ์†Œํ™”
14+
- (3) ํšŒ์ „ ์ค‘์‹ฌ ์ขŒํ‘œ ์—ด(row)์ด ์ตœ์†Œ -> ํ–‰ ์ตœ์†Œ
15+
16+
17+
2. ์œ ๋ฌผ ํš๋“
18+
- 3๊ฐœ ๊ฐ™์€ ์ข…๋ฅ˜ ์ด์›ƒํ•˜๋ฉด -> ์‚ฌ๋ผ์ง€๋Š” ์กฐ๊ฐ ๊ฐœ์ˆ˜ = ์œ ๋ฌผ ๊ฐ€์ง€ => ํ•„ํŠธ์— ๋น”
19+
- ์ƒ์„ฑ ์ˆœ์„œ๋Š” ์œ ์  ๋ฒฝ๋ฉด ์ˆœ์„œ -> ์—ด์ด ์ž‘์€ ์ชฝ -> & ํ–‰ ํฐ๊ฒƒ ์ˆœ์„œ up
20+
- ์กฐ๊ฐ ๊ณ ๊ฐˆ ๋ฌธ์ œ๋Š” ์—†์Œ, ๋‹จ ์‚ฌ์šฉํ•œ ์กฐ๊ฐ์€ ์žฌํ™œ์šฉ x >
21+
22+
3. ํƒ์‚ฌ ๋ฐ˜๋ณต (์ถœ๋ ฅ์กฐ๊ฑด)
23+
- K๋ฒˆ (1๋ฒˆ : ํƒ์‚ฌ์ง„ํ–‰ -> ์œ ๋ฌผํš๋“) => ํš๋“ ์œ ๋ฌผ ๊ฐ€์น˜ ์ถœ๋ ฅ
24+
- ์ค‘๊ฐ„ ํš๋“ ์œ ๋ฌผ ๋ฐฉ๋ฒ• ์กด์žฌ x -> ์ข…๋ฃŒ (์ถœ๋ ฅ : x )
25+
26+
"""
27+
28+
"""
29+
<์ „์ฒด flow>
30+
# 0. ๋ณ€์ˆ˜ ์ž…๋ ฅ : ํƒ์‚ฌ ํšŒ์ˆ˜ K , ์œ ๋ฌผ ์ŠคํŽ˜์–ด ๊ฐœ์ˆ˜ M
31+
### K ๋ฒˆ ๋ฐ˜๋ณต
32+
# ์ค‘์‹ฌ์ขŒํ‘œ ํ›„๋ณด๊ตฐ 9๊ฐœ / ๊ฐ๋„ ํ›„๋ณด๊ตฐ 3๊ฐœ -> 27๋ฒˆ ๋ฐ˜๋ณต
33+
#1. def ํšŒ์ „(์ค‘์‹ฌ์ขŒํ‘œ, ๊ฐ๋„)
34+
35+
#2. ์œ ๋ฌผ ํš๋“ -> ์œ ๋ฌผ ๊ฐ€์น˜ ์ €์žฅ
36+
#-> 27๋ฒˆ ๋ฐ˜๋ณต
37+
#3. ํ•ด๋‹น ํ„ด์—์„œ Best choice ์ธ ์ƒํ™ฉ ๊ฒฐ์ •
38+
# 3.์œ ๋ฌผ ์—…๋ฐ์ดํŠธ
39+
###
40+
"""
41+
"""
42+
input : ์ค‘์‹ฌ ์ขŒํ‘œ, angle , field
43+
ouptut : ๋ณ€ํ™˜๋œ field
44+
45+
์œ„์น˜ idx :
46+
[[i-1 , j-1], [i-1, j],[i-1,j+1],[i+1,j-1] , [i,j] [ i,j+1], [i+1,j-1],[i+1,j],[i+1,j+1]]
47+
90 = [7,5,1,8,5,2,9,6,3]
48+
80 = [7,8,9,4,5,6,1,2,3]
49+
270 = [1,4,7,2,5,8,3,6,9]
50+
"""
51+
"""
52+
# ์œ ๋ฌผ ํš๋“ ํ•จ์ˆ˜ : BFS
53+
# ํ˜„ field ์ƒํ™ฉ์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜
54+
def get_old (field):
55+
"""
56+
57+
# ์ค‘์‹ฌ ์ขŒํ‘œ ํ›„๋ณด๊ตฐ +
58+
# 0. ์ž…๋ ฅ ๋ณ€์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ
59+
K , M = map(int, input().split())
60+
# 0-1. ์ดˆ๊ธฐ ํ•„๋“œ ๊ฐ’ ๋ฐ›๊ธฐ
61+
62+
sfield = [list(map(int,input().split())) for _ in range(5) ]
63+
wall = list(map(int, input().split()))
64+
# ์ƒํ•˜์ขŒ์šฐ
65+
dy = [-1,1,0,0]
66+
dx = [0,0,-1,1]
67+
68+
69+
# (1) 90/180/270 ํšŒ์ „ ํ•จ์ˆ˜
70+
def rotate(i,j, angle ,field) :
71+
old_33=[[i-1 , j-1], [i-1, j],[i-1,j+1],[i+1,j-1] , [i,j] ,[ i,j+1], [i+1,j-1],[i+1,j],[i+1,j+1]]
72+
ro_pos =[]
73+
if angle == "90":
74+
ro_pos = [6,4,0,7,4,1,8,5,2]
75+
elif angle == "180":
76+
ro_pos = [6,7,8,3,4,5,0,1,2]
77+
else:
78+
ro_pos = [0,3,6,1,4,7,2,5,8]
79+
new_field = [row[:] for row in field]
80+
for p in range(0,9):
81+
82+
old = field[old_33[p][0]][old_33[p][1]]
83+
new_field[old_33[ro_pos.index(p)][0]][old_33[ro_pos.index(p)][1]] = old
84+
return field
85+
86+
# ํ˜„ field ์ƒํ™ฉ์—์„œ ๊ฐ€์น˜ ์—…๋ฐ์ดํŠธ
87+
def get_old (field):
88+
del_pos = []
89+
visited = [] # ๋ฐฉ๋ฌธ ์—ฌ๋ถ€
90+
oldest = [] # ๊ฐ start point์—์„œ ์—ฐ๊ฒฐ๋œ ์œ ๋ฌผ ์œ„์น˜
91+
for i in range(5):
92+
for j in range(5):
93+
if [i,j] not in visited :
94+
# start point์™€ ๊ฐ™์€ ์ข…๋ฅ˜์˜ ์œ ๋ฌผ๋งŒ ํš๋“ ๊ฐ€๋Šฅ
95+
q = []
96+
q.append([i,j])
97+
visited.append([i,j])
98+
while q :
99+
cy,cx = q.pop()
100+
for d in range(4) :
101+
ny , nx = cy + dy[d] , cx + dx[d]
102+
if 0 <= ny < 5 and 0 <= nx < 5 :
103+
if [ny,nx] not in visited and field[ny][nx] == field[cy][cx]:
104+
q.append([ny,nx])
105+
visited.append([ny,nx])
106+
oldest.append([ny,nx])
107+
108+
# ํš๋“ ์žˆ์œผ๋ฉด -> ์œ ๋ฌผ ๊ฐœ์ˆ˜ + ์œ„์น˜ ๋ˆ„์ 
109+
if len(oldest) >= 3 : # 3๊ฐœ ์ด์ƒ ์—ฐ๊ฒฐ์‹œ ํš๋“ ๊ฐ€๋Šฅ
110+
del_pos.extend(oldest)
111+
# print(del_pos)
112+
oldest.clear()
113+
114+
return len(del_pos) , del_pos
115+
# best ์ƒํ™ฉ ์„ ํƒ
116+
def cur_best(current_case):
117+
arr = sorted(current_case , key=lambda x : (-x[0] , x[1] , x[2], x[3]))
118+
return arr[0]
119+
120+
121+
answer = []
122+
123+
for k in range(K):
124+
current_case = [] # 27๊ฒฝ์šฐ [์œ ๋ฌผ๊ฐ€์ง€, ๊ฐ๋„ , ์—ด, ํ–‰ ,์‚ญ์ œ ์œ„์น˜ ]
125+
# 9๊ฐœ์˜ ์ค‘์‹ฌ์ขŒํ‘œ ํ›„๋ณด๊ตฐ
126+
ro_sub = [90,180,270]
127+
center_sub= [[1,1], [1,2],[1,3],[2,1] ,[2,2] ,[2,3],[3,1],[3,2],[3,3]]
128+
for center_y , center_x in center_sub :
129+
for ro_angle in ro_sub :
130+
sub_field = rotate(center_y,center_x, ro_angle ,sfield)
131+
value_sub , del_sub = get_old (sub_field)
132+
current_case.append([value_sub, ro_angle, center_y, center_x, sub_field ,del_sub])
133+
134+
#3. ํ•ด๋‹น ํ„ด์—์„œ ๋ฒ ์ŠคํŠธ ์ƒํ™ฉ 1๊ฐœ ์„ ํƒ
135+
# value ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ -> ๋
136+
if len(current_case) <= 0 :
137+
break
138+
best_sit=cur_best(current_case)
139+
answer.append(best_sit[0])
140+
#4. fiedl ์ƒํ™ฉ ์—…๋ฐ์ดํŠธ
141+
# ์œ ๋ฌผ ๋งค๊พธ๊ธฐ - sort๋กœ ์‚ญ์ œ๋œ ์œ„์น˜ ์ •๋ ฌ ํ›„ wall(์œ ๋ฌผ๋ฒฝ๋ฉด) ์ˆ˜ํ–‰
142+
arr = sorted(best_sit[-1] , key = lambda x : (x[0] , -x[1])) # ์‚ฌ๋ผ์ง„ ์œ ๋ฌผ ์œ„์น˜
143+
sfield = best_sit[-2]
144+
pointer = 0
145+
for y,x in arr :
146+
node = wall[pointer]
147+
sfield[y][x] = node
148+
pointer= (pointer+1)%len(wall)
149+
150+
print(answer)

0 commit comments

Comments
ย (0)