Upload files to "백준"
This commit is contained in:
32
백준/1715.py
Normal file
32
백준/1715.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import sys
|
||||||
|
import heapq
|
||||||
|
|
||||||
|
sys.setrecursionlimit(10**6)
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
min_heap = []
|
||||||
|
|
||||||
|
N=int(input().rstrip())
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
heapq.heappush(min_heap, int(input().rstrip()))
|
||||||
|
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
first_value = heapq.heappop(min_heap)
|
||||||
|
result += first_value
|
||||||
|
while min_heap:
|
||||||
|
second_value = heapq.heappop(min_heap)
|
||||||
|
result+=second_value
|
||||||
|
if min_heap:
|
||||||
|
heapq.heappush(min_heap, first_value + second_value)
|
||||||
|
first_value=heapq.heappop(min_heap)
|
||||||
|
result += first_value
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
if(N==1):
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
print(result)
|
||||||
22
백준/1722.py
Normal file
22
백준/1722.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import sys
|
||||||
|
from itertools import permutations
|
||||||
|
import math
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
problem = list(map(int, input().split())) #problem이 주어진 문제
|
||||||
|
|
||||||
|
a=[]
|
||||||
|
for i in range(1, N+1):
|
||||||
|
a.append(i) # a는 순서대로 순열 있는거
|
||||||
|
|
||||||
|
if problem[0] == 1:
|
||||||
|
print(*arr[problem[1]-1])
|
||||||
|
elif problem[0] == 2:
|
||||||
|
for i in range(1, N+1):
|
||||||
|
new_arr.append(problem[i]) # new_arr가 배열만 저장되어 있는거
|
||||||
|
temp = 1
|
||||||
|
for i in arr:
|
||||||
|
if(list(i) == new_arr):
|
||||||
|
print(temp)
|
||||||
|
break
|
||||||
|
temp += 1
|
||||||
57
백준/1744.py
Normal file
57
백준/1744.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import heapq
|
||||||
|
import sys
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
maxheap=[]
|
||||||
|
minheap=[]
|
||||||
|
result = 0
|
||||||
|
count_0 = 0
|
||||||
|
count_1 = 0
|
||||||
|
N = int(input().rstrip())
|
||||||
|
|
||||||
|
def plusnum(num):
|
||||||
|
maxheap.append(num)
|
||||||
|
|
||||||
|
def minusnum(num):
|
||||||
|
minheap.append(num)
|
||||||
|
|
||||||
|
for i in range(N):
|
||||||
|
num = int(input().rstrip())
|
||||||
|
if(num==0):
|
||||||
|
count_0 += 1
|
||||||
|
elif(num==1):
|
||||||
|
count_1 += 1
|
||||||
|
elif(num>0):
|
||||||
|
plusnum(num)
|
||||||
|
else:
|
||||||
|
minusnum(num)
|
||||||
|
|
||||||
|
maxheap.sort()
|
||||||
|
minheap.sort()
|
||||||
|
|
||||||
|
while maxheap:
|
||||||
|
first_value = maxheap.pop()
|
||||||
|
if maxheap:
|
||||||
|
second_value = maxheap.pop()
|
||||||
|
result += (first_value * second_value)
|
||||||
|
else:
|
||||||
|
result += first_value
|
||||||
|
|
||||||
|
if (len(minheap)%2==1):
|
||||||
|
if count_0 and minheap:
|
||||||
|
minheap.pop()
|
||||||
|
else:
|
||||||
|
result+=minheap.pop()
|
||||||
|
|
||||||
|
while minheap:
|
||||||
|
first_value = minheap.pop()
|
||||||
|
second_value = minheap.pop()
|
||||||
|
result += (first_value * second_value)
|
||||||
|
|
||||||
|
result+=count_1
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
29
백준/1747.py
Normal file
29
백준/1747.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import sys
|
||||||
|
import math
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
def pellindrom(num):
|
||||||
|
num = str(num)
|
||||||
|
num_len = len(num) // 2
|
||||||
|
for i in range(num_len):
|
||||||
|
if(num[i]!=num[-(i+1)]):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def isPrime(num):
|
||||||
|
if (num==1):
|
||||||
|
return False
|
||||||
|
for i in range(2, (int(math.sqrt(num))+1)):
|
||||||
|
if num%i == 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if (isPrime(N) and pellindrom(N)):
|
||||||
|
print(N)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
N+=1
|
||||||
34
백준/1753.py
Normal file
34
백준/1753.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import sys
|
||||||
|
input = sys.stdin.readline
|
||||||
|
from queue import PriorityQueue
|
||||||
|
|
||||||
|
V, E = map(int, input().split())
|
||||||
|
K = int(input())
|
||||||
|
distance = [sys.maxsize] * (V+1)
|
||||||
|
visited = [False] * (V+1)
|
||||||
|
myList = [[] for _ in range(V+1)]
|
||||||
|
q = PriorityQueue()
|
||||||
|
|
||||||
|
for _ in range(E):
|
||||||
|
u, v, w = map(int, input().split())
|
||||||
|
myList[u].append((v, w))
|
||||||
|
|
||||||
|
q.put((0, K))
|
||||||
|
distance[K] = 0
|
||||||
|
|
||||||
|
while q.qsize() > 0 :
|
||||||
|
current = q.get()
|
||||||
|
c_v = current[1]
|
||||||
|
if visited[c_v]:
|
||||||
|
continue
|
||||||
|
visited[c_v] = True
|
||||||
|
for next, value in myList[c_v]:
|
||||||
|
if distance[next] > distance[c_v] + value:
|
||||||
|
distance[next] = distance[c_v] + value
|
||||||
|
q.put((distance[next], next))
|
||||||
|
|
||||||
|
for i in range(1, V+1):
|
||||||
|
if visited[i]:
|
||||||
|
print(distance[i])
|
||||||
|
else:
|
||||||
|
print("INF")
|
||||||
Reference in New Issue
Block a user