Upload files to "백준"
This commit is contained in:
57
백준/1111.py
Normal file
57
백준/1111.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import sys
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
n = int(input())
|
||||
arr = list(map(int, input().split()))
|
||||
|
||||
if(n==1):
|
||||
print('A')
|
||||
elif(n==2):
|
||||
print('A')
|
||||
elif(arr[1]==arr[0]):
|
||||
flag = False
|
||||
for i in range(1, n):
|
||||
if(arr[i]!=arr[0]):
|
||||
flag = True
|
||||
if flag:
|
||||
print('B')
|
||||
else:
|
||||
print(arr[0])
|
||||
elif(n>2 and arr[2]-arr[1] == arr[1]-arr[0]):
|
||||
d = arr[1]-arr[0]
|
||||
flag = False
|
||||
for i in range(1, n):
|
||||
if(arr[i]-arr[i-1]!=d):
|
||||
flag = True
|
||||
if flag:
|
||||
print('B')
|
||||
else:
|
||||
print(arr[n-1]+d)
|
||||
elif(n>2 and arr[2]//arr[1] == arr[1]//arr[0]):
|
||||
d = arr[1]//arr[0]
|
||||
if(arr[1]/arr[0] < 1 and arr[1]*arr[0]<0):
|
||||
print('B')
|
||||
exit()
|
||||
flag = False
|
||||
for i in range(1, n):
|
||||
if(arr[i]//arr[i-1]!=d):
|
||||
flag = True
|
||||
if flag:
|
||||
print('B')
|
||||
else:
|
||||
print(arr[n-1]*d)
|
||||
else:
|
||||
if (arr[1] - arr[0]) == 0:
|
||||
print('B')
|
||||
exit()
|
||||
a = (arr[2] - arr[1]) // (arr[1] - arr[0])
|
||||
b = (arr[2] + arr[1] - (arr[1] + arr[0]) * a) // 2
|
||||
flag = False
|
||||
for i in range(1, n):
|
||||
if arr[i] != arr[i - 1] * a + b:
|
||||
flag = True
|
||||
if flag:
|
||||
print('B')
|
||||
else:
|
||||
print(arr[n - 1] * a + b)
|
||||
12
백준/1167.py
Normal file
12
백준/1167.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import sys
|
||||
|
||||
V = sys.stdin.readline().rstrip()
|
||||
V = int(V)
|
||||
arr = [[] * V for i in range(V)]
|
||||
result = [V for i in range(V)]
|
||||
|
||||
for i in range (V):
|
||||
arr[i]=(list(map(int, input().split())))
|
||||
|
||||
for i in range(V):
|
||||
arr[i]=
|
||||
39
백준/1238.py
Normal file
39
백준/1238.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
import heapq
|
||||
|
||||
sys.setrecursionlimit(10**6)
|
||||
input = sys.stdin.readline
|
||||
|
||||
N, M, X = map(int, input().split()) # 학생수, 총 도로수, 가야하는 마을
|
||||
graph = [[] for i in range(N+1)]
|
||||
|
||||
for _ in range(M):
|
||||
a, b, c = map(int, input().split())
|
||||
graph[a].append((b, c))
|
||||
|
||||
|
||||
def dijkstra(start):
|
||||
dist = [sys.maxsize] * (N+1)
|
||||
q = []
|
||||
heapq.heappush(q, (0, start))
|
||||
dist[start] = 0
|
||||
while q:
|
||||
distance, now = heapq.heappop(q)
|
||||
if dist[now]<distance:
|
||||
continue
|
||||
for next in graph[now]:
|
||||
cost = distance + next[1]
|
||||
if cost < dist[next[0]]:
|
||||
dist[next[0]] = cost
|
||||
heapq.heappush(q, (cost, next[0]))
|
||||
return dist
|
||||
|
||||
#다익스트라 알고리즘 실행
|
||||
result_arr = []
|
||||
X_arr = dijkstra(X)
|
||||
|
||||
for i in range(1, N+1):
|
||||
y_arr = dijkstra(i)
|
||||
result_arr.append(y_arr[X] + X_arr[i])
|
||||
|
||||
print(max(result_arr))
|
||||
29
백준/1256.Py
Normal file
29
백준/1256.Py
Normal file
@@ -0,0 +1,29 @@
|
||||
import math
|
||||
import sys
|
||||
from itertools import permutations
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
N, M, K = map(int, input().split())
|
||||
|
||||
total = math.comb(N+M, N)
|
||||
|
||||
if K>total:
|
||||
print(-1)
|
||||
else:
|
||||
result = []
|
||||
while N > 0 and M > 0:
|
||||
count = math.comb(N+M-1, N-1)
|
||||
if K<=count:
|
||||
result.append('a')
|
||||
N -= 1
|
||||
else:
|
||||
result.append('z')
|
||||
M -= 1
|
||||
K -= count
|
||||
|
||||
result.extend(["a"] * N)
|
||||
result.extend(["z"] * M)
|
||||
|
||||
print("".join(result))
|
||||
|
||||
27
백준/1325.py
Normal file
27
백준/1325.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
N, M = map(int, input().split())
|
||||
|
||||
arr=[[] * N for i in range(N)]
|
||||
visited = [False] * (N+1)
|
||||
maxarr = [0] * (N+1)
|
||||
graph = dict()
|
||||
|
||||
for i in range(M):
|
||||
A, B = map(int, input().split())
|
||||
graph[A] = B
|
||||
|
||||
def DFS(graph, start):
|
||||
visited.append(start)
|
||||
for node in graph[start]:
|
||||
if node not in visited:
|
||||
DFS(graph, node, visited)
|
||||
return visited
|
||||
|
||||
DFS(graph, 1)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user