diff --git a/백준/1850.py b/백준/1850.py new file mode 100644 index 0000000..17fb5a4 --- /dev/null +++ b/백준/1850.py @@ -0,0 +1,18 @@ +import math +import sys + +input = sys.stdin.readline + +A, B = map(int, input().split()) + +def GCD(a, b): + if b==0: + return a + else: + return GCD(b, a%b) + +result = GCD(A, B) + +while result > 0 : + print(1, end='') + result -= 1 \ No newline at end of file diff --git a/백준/1865.py b/백준/1865.py new file mode 100644 index 0000000..f4b591c --- /dev/null +++ b/백준/1865.py @@ -0,0 +1,46 @@ +import sys +input = sys.stdin.readline + +#문제는 음수사이클이 존재하냐? 고 묻는 전형적인 벨만포드 문제 +INF = sys.maxsize +tc = int(input()) +for _ in range(tc): + n, m, w = map(int, input().split()) # 지점의 수, 도로의 개수, 웜홀의 개수 + graph = [[] for _ in range(n+1)] + value = False + for _ in range(m): + s, e, t = map(int, input().split()) # s,e는 연결된 지점번호 t는 가중치 + graph[s].append((e, t)) + graph[e].append((s, t)) + + for _ in range(w): + s, e, t = map(int, input().split()) # s,e는 연결된 지점번호 t는 감소가중치 + graph[s].append((e, -t)) + + dist = [INF for _ in range(n+1)] + dist[0] = 0 + for i in range(1, n+1): + graph[0].append((i, 0)) + + for i in range(1, n+1): + for current_node in range(0, n+1): + if dist[current_node] == INF: + continue + for next_node, weight in graph[current_node]: + if dist[current_node] + weight < dist[next_node]: + dist[next_node] = dist[current_node] + weight + for current_node in range(0, n+1): + if dist[current_node] == INF: + continue + for next_node, weight in graph[current_node]: + if dist[current_node] + weight < dist[next_node]: + value = True + break + if value: + break + + if value: + print('YES') + else: + print('NO') + diff --git a/백준/1915.py b/백준/1915.py new file mode 100644 index 0000000..88df2c9 --- /dev/null +++ b/백준/1915.py @@ -0,0 +1,20 @@ +import sys + +input = sys.stdin.readline + +m, n = map(int, input().split()) +arr = [] +detect = False +for i in range(m): + arr.append(list(map(int, input().rstrip()))) + +for x in range(1, m): + for y in range(1, n): + if(arr[x-1][y-1] and arr[x][y-1] and arr[x-1][y] and arr[x][y]): + arr[x][y] = min(arr[x-1][y-1], arr[x][y-1], arr[x-1][y]) + 1 +k=max(map(max, arr)) + +if(k==0): + print(k) +else: + print(k*k) \ No newline at end of file diff --git a/백준/1916.py b/백준/1916.py new file mode 100644 index 0000000..fd00133 --- /dev/null +++ b/백준/1916.py @@ -0,0 +1,34 @@ +import sys +from queue import PriorityQueue + +input = sys.stdin.readline + +n = int(input()) # 도시 개수 +m = int(input()) # 버스 개수 +dist = [sys.maxsize] * (n+1) + +myList = [[] for i in range(n+1)] +visited = [False] * (n+1) + +for i in range(m): + s, e, w = map(int, input().split()) + myList[s].append((e,w)) + +start, end = map(int, input().split()) #시작 도시, 종료 도시 + +def dijkstra(start, end): + queue = PriorityQueue() + queue.put((0, start)) + dist[start] = 0 + while (queue.qsize()>0): + nowNode = queue.get() + now = nowNode[1] + if not visited[now]: + visited[now] = True + for n in myList[now]: + if not visited[n[0]] and dist[n[0]] > dist[now]+n[1]: + dist[n[0]] = dist[now]+n[1] + queue.put((dist[n[0]], n[0])) + return dist[end] + +print(dijkstra(start, end)) \ No newline at end of file diff --git a/백준/1918.py b/백준/1918.py new file mode 100644 index 0000000..e344871 --- /dev/null +++ b/백준/1918.py @@ -0,0 +1,29 @@ +import sys + +input = sys.stdin.readline + +result = [] #숫자들 스택 +calc_stack = [] #연산기호 스택 + +arr = list(map(str, input().strip())) + +precedence = {'+' : 1, '-': 1, '*' : 2, '/' : 2} + +for index in arr: + if index.isalpha(): + result.append(index) + elif index == '(': + calc_stack.append(index) + elif index == ')': + while calc_stack and calc_stack[-1]!='(': + result.append(calc_stack.pop()) + calc_stack.pop() + else: + while calc_stack and calc_stack[-1]!='(' and precedence[index] <= precedence[calc_stack[-1]] : + result.append(calc_stack.pop()) + calc_stack.append(index) + +while calc_stack: + result.append(calc_stack.pop()) + +print(''.join(result)) \ No newline at end of file