baekjoon 20251215-17

This commit is contained in:
songyc macbook 2025-12-17 17:31:32 +09:00
parent 80a44165ae
commit 346dc68487
4 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,33 @@
import java.util.*;
public class _9527 {
static long[] power2 = new long[55];
static long getCountOne(long N) {
long ans = 0;
for(int i = 54; i>0; i--) {
long mark = (N & (1L << (i-1)));
if(mark != 0) {
ans += power2[i-1] + (N - mark + 1);
N -= mark;
}
}
return ans;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long A = sc.nextLong();
long B = sc.nextLong();
sc.close();
for(int i=1; i<55; i++) {
power2[i] = 2*power2[i-1] + (1L << (i-1));
}
System.out.println(getCountOne(B) - getCountOne(A-1));
}
}

View File

@ -0,0 +1,36 @@
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
parents = [i for i in range(n)]
rank = [0]*n
def find(x):
if parents[x] != x:
parents[x] = find(parents[x])
return parents[x]
def union(x, y) :
x = find(x)
y = find(y)
if x == y : return False
if rank[x] > rank[y] :
parents[y] = x
else :
parents[x] = y
if rank[x] == rank[y] :
rank[y] += 1
return True
ans = 0
for i in range(m) :
a, b = map(int, input().split())
if not union(a,b) :
ans = i+1
break
print(ans)

View File

@ -0,0 +1,3 @@
print(". . .")
print("| | _ | _. _ ._ _ _")
print("|/\|(/.|(_.(_)[ | )(/.")

View File

@ -0,0 +1 @@
print("SHIP NAME CLASS DEPLOYMENT IN SERVICE\nN2 Bomber Heavy Fighter Limited 21 \nJ-Type 327 Light Combat Unlimited 1 \nNX Cruiser Medium Fighter Limited 18 \nN1 Starfighter Medium Fighter Unlimited 25 \nRoyal Cruiser Light Combat Limited 4 ")