From 66464134ce1b84ac268d426491ce7a578902b9a7 Mon Sep 17 00:00:00 2001 From: SUMIN Date: Sat, 11 Apr 2026 11:46:51 +0900 Subject: [PATCH] =?UTF-8?q?Upload=20files=20to=20"=EB=B0=B1=EC=A4=80"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 백준/1016_re.py | 24 ++++++++++++++++++++ 백준/1021.py | 32 +++++++++++++++++++++++++++ 백준/1033.py | 43 +++++++++++++++++++++++++++++++++++ 백준/1043.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 백준/1074.py | 42 +++++++++++++++++++++++++++++++++++ 5 files changed, 200 insertions(+) create mode 100644 백준/1016_re.py create mode 100644 백준/1021.py create mode 100644 백준/1033.py create mode 100644 백준/1043.py create mode 100644 백준/1074.py diff --git a/백준/1016_re.py b/백준/1016_re.py new file mode 100644 index 0000000..e7377f2 --- /dev/null +++ b/백준/1016_re.py @@ -0,0 +1,24 @@ +import math +import sys + +input = sys.stdin.readline + +min, max = map(int, input().split()) + +arr = [False] * (max - min + 1) + +for i in range(2, int(math.sqrt(max))+1): + pow = i * i + start_index = int(min/pow) + if min % pow != 0: + start_index+=1 + for j in range(start_index, int(max/pow)+1): + arr[int(j*pow-min)]=True + +count = 0 + +for i in range(0, max-min+1): + if not arr[i]: + count += 1 + +print(count) \ No newline at end of file diff --git a/백준/1021.py b/백준/1021.py new file mode 100644 index 0000000..95065da --- /dev/null +++ b/백준/1021.py @@ -0,0 +1,32 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +n, m = map(int, input().split()) +answer_q = deque(map(int ,input().split())) +q = deque() + +for i in range(1, n+1): + q.append(i) + +chance = 0 + +while answer_q: + k = answer_q.popleft() + if (k == q[0]): + q.popleft() + elif(q.index(k)<=len(q)//2): + while(k!=q[0]): + temp = q.popleft() + q.append(temp) + chance += 1 + q.popleft() + else: + while(k!=q[0]): + temp = q.pop() + q.appendleft(temp) + chance += 1 + q.popleft() + +print(chance) \ No newline at end of file diff --git a/백준/1033.py b/백준/1033.py new file mode 100644 index 0000000..29c56e4 --- /dev/null +++ b/백준/1033.py @@ -0,0 +1,43 @@ +import sys +import math + +sys.setrecursionlimit(10**6) + +input = sys.stdin.readline + +N = int(input()) + +A = [[] for i in range(N)] +visited = [False] * (N) +D = [0] * (N) +lcm = 1 + +def gcd(a,b): + if b==0: + return a + else: + return gcd(b, a%b) + +def DFS(v): + visited[v] = True + for i in A[v]: + next = i[0] + if not visited[next]: + D[next] = D[v] * i[2] // i[1] + DFS(next) + +for i in range(N-1): + a, b, p, q = map(int, input().split()) + A[a].append((b, p, q)) + A[b].append((a, q, p)) + lcm *= (p*q // gcd(p, q)) + +D[0] = lcm +DFS(0) +mgcd = D[0] + +for i in range(1, N): + mgcd = gcd(mgcd, D[i]) + +for i in range(N): + print(int(D[i]//mgcd), end=' ') \ No newline at end of file diff --git a/백준/1043.py b/백준/1043.py new file mode 100644 index 0000000..0c44cc8 --- /dev/null +++ b/백준/1043.py @@ -0,0 +1,59 @@ +import sys +import math + +input = sys.stdin.readline + +N, M = map(int, input().split()) + +isNumber = 0 + +trueman = list(map(int, input().split())) + +human = [0] * (51) + +def find(a): + if (a==human[a]): + return a + else: + human[a]=find(human[a]) + return human[a] + +def union(a,b): + a=find(a) + b=find(b) + if a != b: + human[a] = b + +for i in range(51): + human[i] = i + +trueman_set = [] + +if trueman[0]: # trueman 숫자 정상이라면, + trueman_set = trueman[1:] + + +find_trueman_set=[] + +for i in trueman_set: + find_trueman_set.append(find(i)) + +#각 한 줄에 대해서 루트를 설정해주면 된다! 유니온을 통해서 + +lst = [] +for i in range(M): + temp = list(map(int, input().split())) + lst.append(temp) + if (temp[0]>1): + for i in range(2, temp[0]+1): + union(temp[1], temp[i]) + +find_trueman_set = {find(x) for x in trueman_set} + +# 각 파티에서 대표 노드가 진실을 아는 그룹과 연결되지 않았는지 확인 +for party in lst: + if find(party[1]) not in find_trueman_set: + isNumber += 1 + +print(isNumber) + diff --git a/백준/1074.py b/백준/1074.py new file mode 100644 index 0000000..d02c785 --- /dev/null +++ b/백준/1074.py @@ -0,0 +1,42 @@ +import sys + +# 표준 입력을 빠르게 받기 위한 함수 재정의 +input = sys.stdin.readline +# 재귀 깊이 제한을 크게 설정하여 재귀 함수가 깊게 호출되어도 문제 없도록 함 +sys.setrecursionlimit(10**6) + +# N: 2^N x 2^N 크기의 배열, r: 행 번호, c: 열 번호 +N, r, c = map(int, input().split()) + +def squared(n, r, c, tot): + # 현재 정사각형의 크기를 계산 (2^n x 2^n) + next_right, next_height = 2**n, 2**n + # 기저 사례: 정사각형의 크기가 2x2가 되었을 때 각 칸에 대해 순서를 결정 + if (n == 1 and r == 0 and c == 0): + return tot # 왼쪽 위: 현재까지 누적된 tot 반환 + elif (n == 1 and r == 0 and c == 1): + return tot + 1 # 오른쪽 위: tot에 1을 더해 반환 + elif (n == 1 and r == 1 and c == 0): + return tot + 2 # 왼쪽 아래: tot에 2를 더해 반환 + elif (n == 1 and r == 1 and c == 1): + return tot + 3 # 오른쪽 아래: tot에 3을 더해 반환 + + # 재귀 호출을 통해 현재 정사각형을 4개 분할 (사분면)하여 타겟 위치가 있는 사분면 선택 + # 1사분면: 왼쪽 위 + if (r < next_right // 2 and c < next_height // 2): + return squared(n - 1, r, c, tot) + # 2사분면: 오른쪽 위 + elif (r < next_right // 2): + # 타겟이 오른쪽 위에 있으므로 왼쪽 위 사분면의 칸 수만큼 tot에 더해줌 + return squared(n - 1, r, c - (2**(n - 1)), tot + 2 ** (2*n - 2)) + # 3사분면: 왼쪽 아래 + elif (c < next_height // 2): + # 타겟이 왼쪽 아래에 있으므로 위쪽 두 사분면의 칸 수만큼 tot에 더해줌 + return squared(n - 1, r - (2**(n - 1)), c, tot + 2 ** (2*n - 1)) + # 4사분면: 오른쪽 아래 + else: + # 타겟이 오른쪽 아래에 있으므로 왼쪽 위, 오른쪽 위, 왼쪽 아래 사분면의 칸 수 합만큼 tot에 더해줌 + return squared(n - 1, r - (2**(n - 1)), c - (2**(n - 1)), tot + (2 ** (2*n - 2) + 2 ** (2*n - 1))) + +# 재귀 함수를 호출하여 결과를 출력 +print(squared(N, r, c, 0))