백준문제 6

[백준] 2470번 두 용액 파이썬 풀이

2470번: 두 용액 첫째 줄에는 전체 용액의 수 N이 입력된다. N은 2 이상 100,000 이하이다. 둘째 줄에는 용액의 특성값을 나타내는 N개의 정수가 빈칸을 사이에 두고 주어진다. 이 수들은 모두 -1,000,000,000 이상 1,000,00 www.acmicpc.net [문제] [코드] import sys input = sys.stdin.readline N = int(input()) solution = sorted(list(map(int, input().split()))) ##투포인터 start = 0 end = N-1 target = abs(solution[0] + solution[-1])#절대값 -> 0까지 거리 result = [solution[0], solution[-1]] #초기값 설..

[백준] 1240번 노드사이의 거리 파이썬 풀이

1240번: 노드사이의 거리 N(2≤N≤1,000)개의 노드로 이루어진 트리가 주어지고 M(M≤1,000)개의 두 노드 쌍을 입력받을 때 두 노드 사이의 거리를 출력하라. www.acmicpc.net [문제] [코드] import sys from collections import deque input = sys.stdin.readline n, m = map(int, input().split()) tree = [[] for _ in range(n+1)] #indexing을 위해서 +1사이즈로 구성 #두노드 사이 거리를 구하는 bfs def bfs(a, b): q = deque() q.append((a, 0)) visited = [False] * (n+1) visited[a] = True while q: s..

[백준] 1717번 집합의 표현 Python 파이썬 풀이

1717번: 집합의 표현 첫째 줄에 n(1 ≤ n ≤ 1,000,000), m(1 ≤ m ≤ 100,000)이 주어진다. m은 입력으로 주어지는 연산의 개수이다. 다음 m개의 줄에는 각각의 연산이 주어진다. 합집합은 0 a b의 형태로 입력이 주어진다. 이는 www.acmicpc.net [문제] [코드] import sys sys.setrecursionlimit(1000000) input = sys.stdin.readline n, m = map(int, input().split()) parent = [i for i in range(n + 1)] def find_parent(x): if parent[x] != x: parent[x] = find_parent(parent[x]) return parent[x]..

[백준] 1339번 단어수학 Python 파이썬 풀이

1339번: 단어 수학 첫째 줄에 단어의 개수 N(1 ≤ N ≤ 10)이 주어진다. 둘째 줄부터 N개의 줄에 단어가 한 줄에 하나씩 주어진다. 단어는 알파벳 대문자로만 이루어져있다. 모든 단어에 포함되어 있는 알파벳은 최대 www.acmicpc.net [문제] [코드] import sys input = sys.stdin.readline reference = {} N = int(input()) words = [] for _ in range(N): word = input().rstrip() words.append(word) for j in range(len(word)): if word[j] in reference: reference[word[j]] += 10 **(len(word)-j-1) else: ref..

[백준] 2108번 통계학 파이썬(Python) 풀이

2108번: 통계학 첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. 입력되는 정수의 절댓값은 4,000을 넘지 않는다. www.acmicpc.net [문제] [코드] import sys from collections import Counter input = sys.stdin.readline def make_count(num): num = sorted(num) print(int(round(sum(num)/len(num),0))) print(num[len(num)//2]) f = Counter(num) b = f.most_common() if len(num) > 1 : if b[0][1] == b[1][1]: print(b[..