Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9-suhyun113 #33

Merged
merged 9 commits into from
Jul 17, 2024
6 changes: 5 additions & 1 deletion suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
| 2์ฐจ์‹œ | 2024.03.29 | ์ˆ˜ํ•™ | [์†Œ์ˆ˜ & ํŒฐ๋ฆฐ๋“œ๋กฌ](https://www.acmicpc.net/problem/1747) | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/9) |
| 3์ฐจ์‹œ | 2024.04.02 | ๊ทธ๋ฆฌ๋”” | [๊ฑฐ์Šค๋ฆ„๋ˆ](https://www.acmicpc.net/problem/14916) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/12) |
| 4์ฐจ์‹œ | 2024.04.06 | DP | [ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜ 5](https://www.acmicpc.net/problem/10870) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/16) |
| 5์ฐจ์‹œ | 2024.04.10 | ์Šคํƒ | [ํฌ๋ ˆ์ธ ์ธํ˜• ๋ฝ‘๊ธฐ ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/64061) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/19) |
| 5์ฐจ์‹œ | 2024.04.10 | ์Šคํƒ | [ํฌ๋ ˆ์ธ ์ธํ˜• ๋ฝ‘๊ธฐ ๊ฒŒ์ž„](https://school.programmers.co.kr/learn/courses/30/lessons/64061) | [#19](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/19) |
| 6์ฐจ์‹œ | 2024.04.14 | ์Šคํƒ | [์ปจํŠธ๋กค ์ œํŠธ](https://school.programmers.co.kr/learn/courses/30/lessons/120853) | [#21](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/21) |
| 7์ฐจ์‹œ | 2024.05.09 | ํŠธ๋ฆฌ | [์›์ˆญ์ด ๋งค๋‹ฌ๊ธฐ](https://www.acmicpc.net/problem/2716) | [#31](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/31) |
| 8์ฐจ์‹œ | 2024.05.14 | ์ˆ˜ํ•™ | [์–ด๋ฆฐ ์™•์ž](https://www.acmicpc.net/problem/1004) | [#32](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/32) |
| 9์ฐจ์‹œ | 2024.05.28 | ๋‹ค์ต์ŠคํŠธ๋ผ | [์ตœ์†Œ๋น„์šฉ ๊ตฌํ•˜๊ธฐ](https://www.acmicpc.net/problem/1916) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/33) |
36 changes: 36 additions & 0 deletions suhyun113/๋‹ค์ต์ŠคํŠธ๋ผ/9-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 1916 : ์ตœ์†Œ๋น„์šฉ ๊ตฌํ•˜๊ธฐ

import heapq

INF = float('inf') # ์ตœ๋Œ€๊ฐ’ ์ •์˜

N = int(input()) # ๋„์‹œ์˜ ๊ฐœ์ˆ˜(๋…ธ๋“œ)
M = int(input()) # ๋ฒ„์Šค์˜ ๊ฐœ์ˆ˜(์—์ง€)

graph = [[] for _ in range(N+1)] # ๊ทธ๋ž˜ํ”„ ์ธ์ ‘ ๋ฆฌ์ŠคํŠธ๋กœ ์ดˆ๊ธฐํ™”(๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋“ค)
distance = [INF] * (N+1) # ๊ฐ ๋…ธ๋“œ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ ๋ฌดํ•œ๋Œ€๋กœ ์ดˆ๊ธฐํ™”

for _ in range(M):
x, y, cost = map(int, input().split()) # x -> y ๋„์‹œ๋กœ ๊ฐ€๋Š” ๋ฐ ํ•„์š”ํ•œ ๋น„์šฉ cost
graph[x].append([y, cost]) # ๊ทธ๋ž˜ํ”„์— ์—์ง€ ์ถ”๊ฐ€

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์‚ฌ์†Œํ•œ ํŒ์ธ๋ฐ, graph์˜ ์ •๋ณด๋Š” "๋ถˆ๋ณ€"์ด๋ฏ€๋กœ (์ธ์ ‘ ๋…ธ๋“œ, ๋น„์šฉ) ์ •๋ณด๋ฅผ list๋กœ ๋„ฃ์ง€ ๋ง๊ณ  tuple๋กœ ๋„ฃ์œผ๋ฉด ๋ฉ”๋ชจ๋ฆฌ์™€ ์†๋„ ์ธก๋ฉด์—์„œ ์•ฝ๊ฐ„ ๊ฐœ์„ ๋ฉ๋‹ˆ๋‹ค :)

graph[x].append((y, cost))


start, end = map(int, input().split()) # ์ถœ๋ฐœ, ๋„์ฐฉ ๋…ธ๋“œ ์ž…๋ ฅ ๋ฐ›๊ธฐ

# ๋‹ค์ต์ŠคํŠธ๋ผ ์•Œ๊ณ ๋ฆฌ์ฆ˜
def Dijkstra(start):
q = [] # ์šฐ์„ ์ˆœ์œ„ ํ ์ƒ์„ฑ
heapq.heappush(q, [0, start]) # ์ถœ๋ฐœํ•  ๋„์‹œ ํ์— ๋„ฃ๊ธฐ([๊ฑฐ๋ฆฌ, ๋…ธ๋“œ] ํ˜•ํƒœ)
distance[start] = 0 # ์‹œ์ž‘ ๋„์‹œ์˜ ๊ฑฐ๋ฆฌ 0์œผ๋กœ ์ดˆ๊ธฐํ™”

while q: # ํ๊ฐ€ ๋นŒ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
weight, node = heapq.heappop(q) # ํ˜„์žฌ ๋…ธ๋“œ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ, ํ˜„์žฌ ๋…ธ๋“œ(ํ์—์„œ ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’)
if distance[node] < weight: # ํ˜„์žฌ ๋…ธ๋“œ๊ฐ€ ์ด๋ฏธ ์ฒ˜๋ฆฌ๋œ ๋…ธ๋“œ์ธ์ง€ ํ™•์ธ
continue
for n, w in graph[node]:
cost = w + weight # ํ˜„์žฌ ๋…ธ๋“œ๋ฅผ ํ†ตํ•ด ์ธ์ ‘ ๋…ธ๋“œ๊นŒ์ง€ ๊ฐ€๋Š” ์ƒˆ๋กœ์šด ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
if distance[n] > cost: # ์ƒˆ๋กœ์šด ๊ฑฐ๋ฆฌ๊ฐ€ ๊ธฐ์กด์— ์ €์žฅ๋œ ๊ฑฐ๋ฆฌ๋ณด๋‹ค ์งง์€์ง€ ํ™•์ธ
distance[n] = cost # ์ตœ๋‹จ ๊ฑฐ๋ฆฌ ๊ฐฑ์‹ 
heapq.heappush(q, [cost, n]) # ์ธ์ ‘ ๋…ธ๋“œ๋ฅผ ์šฐ์„ ์ˆœ์œ„ ํ์— ์ถ”๊ฐ€

Dijkstra(start)
print(distance[end])
42 changes: 42 additions & 0 deletions suhyun113/์ˆ˜ํ•™/8-suhyun113.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 1004 : ์–ด๋ฆฐ ์™•์ž

#include <iostream>
#include <cmath>
using namespace std;

int main() {
int T; // ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜
int x1, y1, x2, y2; // ์ถœ๋ฐœ์ , ๋„์ฐฉ์ 
int n; // ํ–‰์„ฑ์˜ ๊ฐœ์ˆ˜
int cx, cy, r; // ํ–‰์„ฑ๊ณ„์˜ ์ค‘์ ๊ณผ ๋ฐ˜์ง€๋ฆ„

cin >> T;
while(T--) {
cin >> x1 >> y1 >> x2 >> y2;
cin >> n;

int enter = 0; // ์ง„์ž… ํšŸ์ˆ˜
int departure = 0; // ์ดํƒˆ ํšŸ์ˆ˜
int count = 0; // ์ตœ์ข… ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜

while(n--) {
cin >> cx >> cy >> r;
float startDistance = sqrt(pow(cx - x1, 2) + pow(cy - y1, 2)); // ์ถœ๋ฐœ์ ๊ณผ ์› ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ
float endDistance = sqrt(pow(cx - x2, 2) + pow(cy - y2, 2)); // ๋„์ฐฉ์ ๊ณผ ์› ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ

if (startDistance < r){ // ์ถœ๋ฐœ์ ์ด ์› ๋‚ด๋ถ€์— ์žˆ๊ณ ,
if (endDistance > r) { // ๋„์ฐฉ์ ์ด ์› ์™ธ๋ถ€์— ์žˆ์Œ
departure++; // ์ถœ๋ฐœ์  ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ -> ์ดํƒˆ ํšŸ์ˆ˜ ์ฆ๊ฐ€
}
}
if (startDistance > r) { // ์ถœ๋ฐœ์ ์ด ์› ์™ธ๋ถ€์— ์žˆ๊ณ ,
if (endDistance < r) { // ๋„์ฐฉ์ ์ด ์› ๋‚ด๋ถ€์— ์žˆ์Œ
enter++; // ๋„์ฐฉ์  ํฌํ•จํ•˜๋Š” ํ–‰์„ฑ -> ์ง„์ž… ํšŒ์ˆ˜ ์ฆ๊ฐ€
}
}
}
count = enter + departure; // ์ตœ์ข… ์ง„์ž…/์ดํƒˆ ํšŸ์ˆ˜
cout << count << endl;
}
return 0;
}
20 changes: 20 additions & 0 deletions suhyun113/์Šคํƒ/6-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def solution(s):
answer = 0

stack = [float("inf")]

# ๋ฌธ์ž์—ด์„ ๊ณต๋ฐฑ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋ฆฌ์ŠคํŠธ์— ์ €์žฅ
s_list = s.split()

for i in s_list: # i๋Š” s_list์˜ ์ธ๋ฑ์Šค๊ฐ€ ์•„๋‹Œ ๊ฐ’
if i != 'Z':
stack.append(i)
else:
stack.pop() # stack์˜ ๊ฐ€์žฅ ์œ„์˜ ๊ฐ’ ๋นผ๊ธฐ
stack.pop(0)

# ๋ฌธ์ž๋ฅผ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ
for i in stack:
n = int(i)
answer += n
return answer
27 changes: 27 additions & 0 deletions suhyun113/ํŠธ๋ฆฌ/7-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 2716 : ์›์ˆญ์ด ๋งค๋‹ฌ๊ธฐ

N = int(input()) # ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜
results = []

for _ in range(N):
s = input().strip()
len_s = len(s)

depth = 0
max_depth = 0

for i in range(len_s):
if (s[i] == '['):
depth += 1
if (depth > max_depth):
max_depth = depth
elif (s[i] == ']'):
depth -= 1

result = 1 #๋‚˜๋ฌด ๊ผญ๋Œ€๊ธฐ ๋„๋‹ฌ์œ„ํ•ด ์ตœ์†Œ ํ•œ ๋งˆ๋ฆฌ ์›์ˆญ์ด ํ•„์š”
for _ in range(max_depth):
result *= 2
results.append(result)

for result in results:
print(result)