Skip to content

Commit

Permalink
22.08.28
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Aug 28, 2022
1 parent ca30ab3 commit 747d99b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions BAEKJOON/11724_연결_요소의_개수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
def input(): return sys.stdin.readline().strip()

def get(idx):
here = idx
while here != union[here]:
here = union[here]
root, here = here, idx
while here != union[here]:
union[here], here = root, union[here]
return root

N, M = map(int, input().split())
union = [i for i in range(N + 1)]

for _ in range(M):
a, b = map(int, input().split())
union[get(a)] = get(b)
for i in range(1, N + 1):
get(i)
print(len(set(union)) - 1)
17 changes: 17 additions & 0 deletions BAEKJOON/1316_그룹_단어_체커.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
def input(): return sys.stdin.readline().strip()

N, answer = int(input()), 0
for _ in range(N):
check, pre = set(), ''

for ch in input():
if ch != pre:
if ch in check:
break
check.add(ch)
pre = ch
else:
answer = answer + 1

print(answer)
29 changes: 29 additions & 0 deletions BAEKJOON/1992_쿼드트리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import sys
sys.stdin = open("1.txt")
def input(): return sys.stdin.readline().strip()

def dfs(x, y, g):
cnt = psum[y + g - 1][x + g - 1] + psum[y - 1][x - 1]\
- psum[y + g - 1][x - 1] - psum[y - 1][x + g - 1]
if cnt == g ** 2:
return "1"
if cnt == 0:
return "0"

retval = ""
retval = retval + dfs(x, y, g // 2)
retval = retval + dfs(x + g // 2, y, g // 2)
retval = retval + dfs(x, y + g // 2, g // 2)
retval = retval + dfs(x + g // 2, y + g // 2, g // 2)
return f"({retval})"

N = int(input())
data = [list(map(int, input())) for _ in range(N)]
psum = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(N):
for j in range(N):
psum[i][j] = psum[i - 1][j] + psum[i][j - 1]\
- psum[i - 1][j - 1] + data[i][j]

print(dfs(0, 0, N))

0 comments on commit 747d99b

Please sign in to comment.