diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 557bc31f..8e381feb 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -30,6 +30,6 @@ | 26차시 | 2024.08.24 | 그리디 | [신입사원](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 | | 27차시 | 2024.08.27 | DFS | [트리의 지름](https://www.acmicpc.net/problem/1967) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/240 | | 28차시 | 2024.09.04 | 벨만포드 | [타임머신](https://www.acmicpc.net/problem/11657) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/244 | -| 29차시 | 2024.09.06 | 구현 | [톱니바퀴](https://www.acmicpc.net/problem/14891) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/245 | - -## | 31차시 | 2024.10.05 | 정렬 | [선 긋기](https://www.acmicpc.net/problem/2170) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/249 | +| 29차시 | 2024.09.06 | 구현 |[톱니바퀴](https://www.acmicpc.net/problem/14891) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/245 | +| 30차시 | 2024.09.27 | 수학 | [Fly me to the Alpha Centauri](https://www.acmicpc.net/problem/1011) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/248 | +| 31차시 | 2024.10.05 | 정렬 | [선 긋기](https://www.acmicpc.net/problem/2170) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/249 | diff --git "a/H0ngJu/\354\210\230\355\225\231/Fly me to the Alpha Centauri.py" "b/H0ngJu/\354\210\230\355\225\231/Fly me to the Alpha Centauri.py" new file mode 100644 index 00000000..9295f116 --- /dev/null +++ "b/H0ngJu/\354\210\230\355\225\231/Fly me to the Alpha Centauri.py" @@ -0,0 +1,21 @@ +import sys + +def input() : return sys.stdin.readline().rstrip() + +T = int(input()) + +for _ in range(T): + x, y = map(int, input().split()) + distance = y - x + cnt = 0 + + for _ in range(distance+1): + if distance <= cnt**2: + break + else: + cnt += 1 + + if distance <= (cnt-1)*cnt: + print((cnt-1)*2) + else: + print(cnt*2-1) \ No newline at end of file diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index d91cf49d..1c15f36a 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -83,4 +83,5 @@ | 74차시 | 2024.08.30 | BFS | 불 켜기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242 | 75차시 | 2024.09.02 | DP | 산 모양 타일링 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/243 | 76차시 | 2024.09.06 | DFS + 트리 | 표현 가능한 이진트리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246 +| 77차시 | 2024.09.27 | 구현 | 표 병합 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/247 --- diff --git "a/tgyuuAn/\352\265\254\355\230\204/\355\221\234 \353\263\221\355\225\251.py" "b/tgyuuAn/\352\265\254\355\230\204/\355\221\234 \353\263\221\355\225\251.py" new file mode 100644 index 00000000..2eff443e --- /dev/null +++ "b/tgyuuAn/\352\265\254\355\230\204/\355\221\234 \353\263\221\355\225\251.py" @@ -0,0 +1,101 @@ +from collections import defaultdict + +def solution(commands): + table = [[None for _ in range(52)] for _ in range(52)] + linked_dict = defaultdict(set) + value_dict = defaultdict(set) + answer = [] + + for command in commands: + splt = command.split() + length = len(splt) + query = splt[0] + + if query == "UPDATE": + if(length == 3): + value1, value2 = splt[1], splt[2] + + temp = set() + for (r, c) in value_dict[value1]: + table[r][c] = value2 + temp.add((r,c)) + + value_dict[value1] = set() + value_dict[value2].update(temp) + + elif(length == 4): + r, c, value1 = int(splt[1]), int(splt[2]), splt[3] + + origin = table[r][c] + if len(linked_dict[(r,c)]) == 0: + table[r][c] = value1 + value_dict[value1].add((r,c)) + if origin is not None: value_dict[origin].discard((r,c)) + + else: + for (l_r, l_c) in linked_dict[(r,c)]: + if origin is not None: value_dict[origin].discard((l_r, l_c)) + table[l_r][l_c] = value1 + + value_dict[value1].update(linked_dict[(r,c)]) + + elif query == "MERGE": + r1, c1, r2, c2 = int(splt[1]), int(splt[2]), int(splt[3]), int(splt[4]) + + if((r1, c1) == (r2, c2)): continue + value1 = table[r1][c1] + value2 = table[r2][c2] + merge_value = None + if value1 is not None and value2 is not None: + merge_value = value1 + + elif value1 is not None: + merge_value = value1 + + elif value2 is not None: + merge_value = value2 + + all_element = {(r1, c1), (r2, c2)} + + value1_element = {(r1, c1)} | linked_dict[(r1, c1)] + value2_element = {(r2, c2)} | linked_dict[(r2, c2)] + all_element = value1_element | value2_element + + if value1 is None and value2 is not None: + for (el_r, el_c) in value1_element: + table[el_r][el_c] = merge_value + + value_dict[value2].add((el_r, el_c)) + + if not(value1 is None and value2 is None): + for (el_r, el_c) in value2_element: + table[el_r][el_c] = merge_value + + if value1 is not None and value2 is not None: + value_dict[value2].discard((el_r, el_c)) + value_dict[value1].add((el_r, el_c)) + + elif value1 is not None: + value_dict[value2].discard((el_r, el_c)) + value_dict[value1].add((el_r, el_c)) + + for (l_r, l_c) in all_element: + linked_dict[(l_r, l_c)] = all_element + + elif query =="UNMERGE": + r, c = int(splt[1]), int(splt[2]) + value1 = table[r][c] + value_dict[value1] -= linked_dict[(r, c)] + + for (now_r, now_c) in linked_dict[(r, c)]: + linked_dict[(now_r, now_c)] = set() + table[now_r][now_c] = None + + table[r][c] = value1 + value_dict[value1].add((r,c)) + + elif query =="PRINT": + r, c = int(splt[1]), int(splt[2]) + answer.append(table[r][c] if table[r][c] is not None else "EMPTY") + + return answer \ No newline at end of file