Upload files to "백준"
This commit is contained in:
18
백준/1850.py
Normal file
18
백준/1850.py
Normal file
@@ -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
|
||||
46
백준/1865.py
Normal file
46
백준/1865.py
Normal file
@@ -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')
|
||||
|
||||
20
백준/1915.py
Normal file
20
백준/1915.py
Normal file
@@ -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)
|
||||
34
백준/1916.py
Normal file
34
백준/1916.py
Normal file
@@ -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))
|
||||
29
백준/1918.py
Normal file
29
백준/1918.py
Normal file
@@ -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))
|
||||
Reference in New Issue
Block a user