From f584fc30473b7f413bef62f64caf349abfbab58c Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Thu, 11 Jul 2024 07:50:44 +0900 Subject: [PATCH] 2024-07-08 --- "tgyuuAn/BFS/\353\241\234\352\263\240.py" | 59 +++++++++++++++++++++++ tgyuuAn/README.md | 3 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 "tgyuuAn/BFS/\353\241\234\352\263\240.py" diff --git "a/tgyuuAn/BFS/\353\241\234\352\263\240.py" "b/tgyuuAn/BFS/\353\241\234\352\263\240.py" new file mode 100644 index 00000000..c1d00888 --- /dev/null +++ "b/tgyuuAn/BFS/\353\241\234\352\263\240.py" @@ -0,0 +1,59 @@ +import sys +from collections import deque + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) + +can_visit = set() +for _ in range(N): + x1, y1, x2, y2 = map(int,input().split()) + + x1 *= 2 + y1 *= 2 + x2 *= 2 + y2 *= 2 + + for draw_x in range(x1, x2+1): + can_visit.add((draw_x, y1)) + can_visit.add((draw_x, y2)) + + for draw_y in range(y1, y2+1): + can_visit.add((x1, draw_y)) + can_visit.add((x2, draw_y)) + + +dx = [0, 0, -1, 1] +dy = [-1, 1, 0, 0] +can_visit.add((0, 0)) +draw_coordinate = deque(can_visit) +answer = 0 +while draw_coordinate: + deq = deque() + + if (0, 0) in can_visit: + deq.append((0, 0)) + can_visit.discard((0, 0)) + + else: + now_x, now_y = draw_coordinate.popleft() + if (now_x, now_y) not in can_visit: continue + + deq.append((now_x, now_y)) + can_visit.discard((now_x, now_y)) + + while deq: + now_x, now_y = deq.popleft() + + for dir in range(4): + new_x = now_x + dx[dir] + new_y = now_y + dy[dir] + + if (new_x, new_y) not in can_visit: continue + + can_visit.discard((new_x, new_y)) + deq.append((new_x, new_y)) + + answer += 1 + +print(answer-1) \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 9aa8dd65..f73a8180 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -66,5 +66,6 @@ | 59차시 | 2024.06.03 | 다익스트라 + 이분 탐색 | 개미 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/207 | 60차시 | 2024.06.07 | 그리디 | 불 끄기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/209 | 61차시 | 2024.06.20 | 크루스칼 | 우주신과의 교감 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/212 -| 62차시 | 2024.07.01 | DP | 우수 마을 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/214 +| 62차시 | 2024.07.01 | DP | 우수 마을 | https://github.com/AlgoLeadMe/AlgoLeadMse-1/pull/214 +| 63차시 | 2024.07.08 | BFS | 로고 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/216 ---