From 0285aa273ea4ebaed99d314b2f3844ebabe7504e Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Tue, 27 Aug 2024 04:32:25 +0900 Subject: [PATCH 1/3] 2024-08-26 --- tgyuuAn/BFS/Rain (Small).py | 53 +++++++++++++++++++++++++++++++++++++ tgyuuAn/README.md | 1 + 2 files changed, 54 insertions(+) create mode 100644 tgyuuAn/BFS/Rain (Small).py diff --git a/tgyuuAn/BFS/Rain (Small).py b/tgyuuAn/BFS/Rain (Small).py new file mode 100644 index 00000000..0e02ba03 --- /dev/null +++ b/tgyuuAn/BFS/Rain (Small).py @@ -0,0 +1,53 @@ +from collections import deque +import sys + +def input(): return sys.stdin.readline().rstrip() + +dx = [0, 0, -1, 1] +dy = [-1, 1, 0, 0] + +T = int(input()) + +for test_idx in range(T): + row, col = map(int, input().split()) + board = [list(map(int,input().split())) for _ in range(row)] + new_board = [[0 for _ in range(col)] for _ in range(row)] + + for height in range(1, 1001): + for start_row in range(row): + for start_col in range(col): + if board[start_row][start_col] >= height: continue + + deq = deque() + deq.append((start_row, start_col)) + history = {(start_row, start_col),} + + visited = set() + visited.add((start_row, start_col)) + + while deq: + now_row, now_col = deq.popleft() + + # 가장자리에 물이 흘렀다는 것이므로 break + if now_row in (0, row-1): break + if now_col in (0, col-1): break + + for dir in range(4): + new_row = now_row + dy[dir] + new_col = now_col + dx[dir] + + if new_row < 0 or new_row >= row: continue + if new_col < 0 or new_col >= col: continue + if (new_row, new_col) in visited: continue + if board[new_row][new_col] >= height: continue + + deq.append((new_row, new_col)) + history.add((new_row, new_col)) + visited.add((new_row, new_col)) + + # 가장자리에 물이 흐르지 않아 break되지 않았으면, + else: + for history_row, history_col in history: + new_board[history_row][history_col] = height - board[history_row][history_col] + + print(f"Case #{test_idx+1}: {sum([sum(row) for row in new_board])}") \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 73034d56..16b83c60 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -77,4 +77,5 @@ | 68차시 | 2024.08.06 | 그리디 | 가희와 탑 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/226 | 69차시 | 2024.08.10 | 누적합, 수학 | 1의 개수 세기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/228 | 70차시 | 2024.08.16 | 스택 | 탑 보기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232 +| 73차시 | 2024.08.26 | BFS | Rain (Small) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/239 --- From e6ff9a5fd4781c327f0f22f242f9d27790ea6d68 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 27 Aug 2024 23:02:47 +0900 Subject: [PATCH 2/3] 2024-08-27 --- ...4\354\235\230 \354\247\200\353\246\204.py" | 28 +++++++++++++++++++ H0ngJu/README.md | 8 ++++-- ...44\355\212\270\354\225\250\353\262\224.py" | 0 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 "H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" rename "H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" => "H0ngJu/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" (100%) diff --git "a/H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" "b/H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" new file mode 100644 index 00000000..7fb0fd9f --- /dev/null +++ "b/H0ngJu/DFS/\355\212\270\353\246\254\354\235\230 \354\247\200\353\246\204.py" @@ -0,0 +1,28 @@ +import sys +sys.setrecursionlimit(10**9) +def input() : return sys.stdin.readline().rstrip() + +n = int(input()) +tree = [[] for _ in range(n+1)] +visited = [-1] * (n+1) +visited[1] = 0 + +for i in range(n-1): + v, u, w = map(int, input().split()) + tree[v].append((u, w)) + tree[u].append((v, w)) + +def dfs(start, dis): + for node, node_dis in tree[start]: + if visited[node] == -1: + visited[node] = dis + node_dis + dfs(node, dis + node_dis) + +dfs(1,0) + +far_node = visited.index(max(visited)) +visited = [-1] * (n+1) +visited[far_node] = 0 +dfs(far_node, 0) + +print(max(visited)) \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 0ccf56d0..e220aaaa 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -24,8 +24,10 @@ | 20차시 | 2024.06.03 | 백트래킹 | [스타트와 링크](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 | | 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | | 22차시 | 2024.08.06 | 해시 | [의상](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 | -| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | -| 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | -| 25차시 | 2024.08.17 | DFS | [친구비](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | +| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | +| 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | +| 25차시 | 2024.08.17 | DFS | [친구비](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | + +| 27차시 | 2024.08.27 | DFS | [트리의 지름](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 | --- diff --git "a/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" "b/H0ngJu/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" similarity index 100% rename from "H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" rename to "H0ngJu/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" From 6702886d946660386266442cdf7a01ab49f58347 Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Sun, 1 Sep 2024 02:15:51 +0900 Subject: [PATCH 3/3] 74-tgyuuAn --- tgyuuAn/README.md | 1 + .../\353\266\210 \354\274\234\352\270\260.py" | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 "tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 6e403df7..492b2333 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -78,4 +78,5 @@ | 69차시 | 2024.08.10 | 누적합, 수학 | 1의 개수 세기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/228 | 70차시 | 2024.08.16 | 스택 | 탑 보기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232 | 71차시 | 2024.08.20 | 다익스트라 | 다익스트라 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235 +| 74차시 | 2024.08.30 | BFS | 불 켜기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242 --- diff --git "a/tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" "b/tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" new file mode 100644 index 00000000..a29d53b4 --- /dev/null +++ "b/tgyuuAn/\354\231\204\354\240\204 \355\203\220\354\203\211/\353\266\210 \354\274\234\352\270\260.py" @@ -0,0 +1,46 @@ +from collections import deque, defaultdict +import sys + +def input(): return sys.stdin.readline().rstrip() + +N, M = map(int, input().split()) +board = [[False for _ in range(N+1)] for _ in range(N+1)] +board[1][1] = True + +switch = defaultdict(list) + +for _ in range(M): + x, y, a, b = map(int, input().split()) + switch[(x, y)].append((a,b)) + +deq = deque() +deq.append((1,1)) +dx = [0, 0, -1, 1] +dy = [-1, 1, 0, 0] +visited = {(1, 1),} +dedicates = {(1, 1),} + +while deq: + now_x, now_y = deq.popleft() + + for turn_on in switch[(now_x, now_y)]: + if turn_on not in dedicates: # <<<------- 이 코드 한줄에 3시간 날림 + dedicates.add(turn_on) + + if turn_on in visited: + deq.append(turn_on) + + for dir in range(4): + new_x = now_x + dx[dir] + new_y = now_y + dy[dir] + + if new_x <= 0 or new_x >= N+1: continue + if new_y <= 0 or new_y >= N+1: continue + if (new_x, new_y) in visited: continue + + visited.add((new_x, new_y)) + + if (new_x, new_y) in dedicates: + deq.append((new_x, new_y)) + +print(len(dedicates)) \ No newline at end of file