Skip to content

Commit 50036c8

Browse files
authored
Merge pull request #53 from 24-Algorithm/minjeong
Minjeong / 7문제 / 8월 2주차
2 parents 6a44162 + 63a7d33 commit 50036c8

9 files changed

+178
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 감시 영역을 확인하는 함수
5+
def is_safe(n, hallway, teachers):
6+
# 선생님 위치로부터 상하좌우 방향을 장애물/벽을 만날 때까지 계속 이동해보면서 학생 존재 여부 탐색
7+
for x, y in teachers: # (0, 4), (1, 0), (3, 1), (4, 2)
8+
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
9+
nx, ny = x, y
10+
while 0 <= nx < n and 0 <= ny < n:
11+
if hallway[nx][ny] == 'O': # 장애물 만나면 즉시 종료
12+
break
13+
if hallway[nx][ny] == 'S': # 학생이 있으면 감시됨
14+
return False
15+
# 한 쪽 방향으로 장애물 또는 벽을 만날 때까지 계속 이동
16+
nx += dx
17+
ny += dy
18+
# 학생이 없다면 True 반환
19+
return True
20+
21+
def set_obstacles(count):
22+
if count == 3: # 장애물 3개가 설치되면 감시가 안전한지 확인
23+
return is_safe(n, hallway, teachers)
24+
25+
for i in range(n):
26+
for j in range(n):
27+
if hallway[i][j] == 'X':
28+
hallway[i][j] = 'O'
29+
if set_obstacles(count + 1):
30+
return True
31+
hallway[i][j] = 'X'
32+
33+
return False
34+
35+
n = int(input()) # 복도 크기
36+
hallway = [] # 복도 정보
37+
teachers = [] # 선생님 위치 리스트
38+
39+
for i in range(n):
40+
row = list(map(str, input().split()))
41+
hallway.append(row)
42+
for j in range(n):
43+
if hallway[i][j] == 'T':
44+
teachers.append((i, j))
45+
46+
if set_obstacles(0):
47+
print("YES")
48+
else:
49+
print("NO")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N = int(input()) # 배열의 크기
5+
k = int(input()) # 찾고자 하는 k번째 작은 값의 위치
6+
7+
start, end = 0, N * N # 이분탐색 범위 설정 (0 ~ N*N)
8+
# 이분탐색 시작
9+
while start <= end: # start와 end가 교차되기 전까지 계속 반복
10+
mid = (start + end) // 2
11+
count = 0
12+
# 각 행마다 mid보다 작거나 같은 값이 몇 개인지 세기
13+
for i in range(1, N + 1):
14+
# mid를 i로 나눈 값과 N 중 작은 값을 더함
15+
# 이는 i번째 행에서 mid보다 작거나 같은 값의 개수를 의미
16+
count += min(mid // i, N)
17+
18+
if count < k:
19+
# mid보다 작거나 같은 값의 개수(count)가 k보다 작으면, k번째 값은 더 큰 값 중에 있음
20+
start = mid + 1
21+
else:
22+
# 그렇지 않으면, k번째 값은 더 작은 값 중에 있음
23+
end = mid - 1
24+
25+
# 최종적으로 start 값이 k번째로 작은 값이 됨
26+
print(start)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n, m = map(int, input().split())
5+
dp = [[0] * (m+1) for _ in range(n+1)]
6+
dp[0][0] = 1
7+
for i in range(1, n+1):
8+
for j in range(1, m+1):
9+
dp[i][j] = (dp[i][j-1] + dp[i-1][j] + dp[i-1][j-1]) % 1000000007
10+
11+
print(dp[n][m])
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
burgers, sides, drinks = map(int, input().split())
5+
burger_prices = list(map(int, input().split()))
6+
sides_prices = list(map(int, input().split()))
7+
drinks_prices = list(map(int, input().split()))
8+
9+
# 세트 할인이 적용되기 전 가격
10+
before_price = sum(burger_prices) + sum(sides_prices) + sum(drinks_prices)
11+
12+
# 세트 할인이 적용된 후 최소 가격 계산
13+
burger_prices.sort(reverse=True)
14+
sides_prices.sort(reverse=True)
15+
drinks_prices.sort(reverse=True)
16+
17+
count = min(burgers, sides, drinks)
18+
after_price = 0
19+
20+
# 세트 할인이 적용된 부분
21+
for i in range(count):
22+
set_price = burger_prices[i] + sides_prices[i] + drinks_prices[i]
23+
after_price += set_price * 0.9 # 10% 할인 적용
24+
25+
# 세트 할인이 적용되지 않은 부분
26+
after_price += sum(burger_prices[count:]) + sum(sides_prices[count:]) + sum(drinks_prices[count:])
27+
28+
# 결과 출력
29+
print(before_price)
30+
print(int(after_price))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 이길 수 있는지 확인하는 함수
5+
def can_win(a, b): # 기준, 비교대상
6+
if (a == "S" and b == "P") or (a == "R" and b == "S") or (a == "P" and b == "R"):
7+
return True
8+
return False # 상대방과 비기거나 상대방이 이길 경우는 False
9+
10+
ML, MR, TL, TR = map(str, input().split())
11+
12+
# 민성이가 무조건 이길 수 있는지 확인
13+
ms_can_win = (can_win(ML, TL) and can_win(ML, TR)) or (can_win(MR, TL) and can_win(MR, TR))
14+
15+
# 태경이가 무조건 이길 수 있는지 확인
16+
tk_can_win = (can_win(TL, ML) and can_win(TL, MR)) or (can_win(TR, ML) and can_win(TR, MR))
17+
18+
# 정답 출력
19+
if ms_can_win:
20+
print("MS")
21+
elif tk_can_win:
22+
print("TK")
23+
else:
24+
print("?")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
N, K = map(int, input().split())
5+
li = list(map(int, input().split()))
6+
li.sort()
7+
print(li[K-1])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n = int(input()) # 열의 개수
5+
cipher_txt = input().strip() # 암호화 된 문자
6+
rows = len(cipher_txt) // n # 행의 개수
7+
8+
# 리스트에 채워넣기
9+
arr = []
10+
for i in range(rows):
11+
if i % 2 == 0: # 왼 -> 오
12+
arr.append(cipher_txt[i*n:(i+1)*n])
13+
else: # 오 -> 왼
14+
arr.append(cipher_txt[i*n:(i+1)*n][::-1])
15+
16+
# 원래의 문자열 복원
17+
original = ""
18+
for i in range(n):
19+
for j in range(rows):
20+
original += arr[j][i]
21+
print(original)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
S = input().strip()
5+
suffix = []
6+
for i in range(len(S)):
7+
suffix.append(S[i:])
8+
suffix.sort()
9+
for word in suffix:
10+
print(word)

0 commit comments

Comments
 (0)