diff --git a/froglike6/README.md b/froglike6/README.md index 5ea1f20..7d82e43 100644 --- a/froglike6/README.md +++ b/froglike6/README.md @@ -23,4 +23,7 @@ | 19차시 | 2025.07.04 | 애드 혹 | [서로소 그래프 게임](https://www.acmicpc.net/problem/34035)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/72| | 20차시 | 2025.07.09 | 조합론 | [암호 만들기](https://www.acmicpc.net/problem/1759)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/77| | 21차시 | 2025.07.14 | 기하학 | [Cows](https://www.acmicpc.net/problem/6850)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/82| + | 22차시 | 2025.07.22 | 그래프 | [밤(Time For The Moon Night)](https://www.acmicpc.net/problem/34064)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/88| + | 23차시 | 2025.07.22 | 정수 | [Fibonacci](https://www.acmicpc.net/problem/7677)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/89| + | 24차시 | 2025.08.01 | 구현 | [세그먼트 트리보다도 바・로・너・♡](https://www.acmicpc.net/problem/34075)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/91| --- diff --git a/froglike6/graph_theory/34064.py b/froglike6/graph_theory/34064.py new file mode 100644 index 0000000..c6c9251 --- /dev/null +++ b/froglike6/graph_theory/34064.py @@ -0,0 +1,46 @@ +import sys +input = sys.stdin.readline + +N, M, K = map(int, input().split()) +grid = [[0]*M for _ in range(N)] +for _ in range(K): + x, y = map(int, input().split()) + grid[x-1][y-1] = 1 + +a1, b1 = map(int, input().split()) +a2, b2 = map(int, input().split()) +a3, b3 = map(int, input().split()) +a4, b4 = map(int, input().split()) + +a1, b1, a2, b2 = a1-1, b1-1, a2-1, b2-1 +a3, b3, a4, b4 = a3-1, b3-1, a4-1, b4-1 + +visited = [[False]*M for _ in range(N)] +dirs = [(1,0),(-1,0),(0,1),(0,-1)] +answer = 0 + +for i in range(N): + for j in range(M): + if grid[i][j] == 0 and not visited[i][j]: + stack = [(i, j)] + visited[i][j] = True + countA = 0 + countB = 0 + + while stack: + x, y = stack.pop() + if a1 <= x <= a2 and b1 <= y <= b2: + countA += 1 + if a3 <= x <= a4 and b3 <= y <= b4: + countB += 1 + + for dx, dy in dirs: + nx, ny = x + dx, y + dy + if 0 <= nx < N and 0 <= ny < M: + if grid[nx][ny] == 0 and not visited[nx][ny]: + visited[nx][ny] = True + stack.append((nx, ny)) + + answer += countA * countB + +print(answer) \ No newline at end of file diff --git a/froglike6/implementation/34075.py b/froglike6/implementation/34075.py new file mode 100644 index 0000000..2eadbb2 --- /dev/null +++ b/froglike6/implementation/34075.py @@ -0,0 +1,29 @@ +import sys +input = sys.stdin.readline + +n = int(input()) +algo = [] +for _ in range(n): + name, d = input().split() + algo.append((name, int(d))) + +m = int(input()) +member = {} +for _ in range(m): + name, tier = input().split() + tier = int(tier) + pref = sorted(algo, key=lambda x: (abs(x[1] - tier), x[0])) + best1, best2 = pref[0][0], pref[1][0] + member[name] = (best1, best2) + +q = int(input()) +cur = None + +for _ in range(q): + line = input().strip() + if line.endswith("- chan!"): + cur = line.split(" - ")[0] + print("hai!") + else: + best1, best2 = member[cur] + print(f"{best2} yori mo {best1}") \ No newline at end of file diff --git a/froglike6/number_theory/7677.java b/froglike6/number_theory/7677.java new file mode 100644 index 0000000..3ab6c40 --- /dev/null +++ b/froglike6/number_theory/7677.java @@ -0,0 +1,53 @@ +import java.io.*; +import java.util.*; + +public class Main { + private static final int MOD = 10000; + + public static int fibo(long n) { + long m00 = 1, m01 = 1, m10 = 1, m11 = 0; + long v0 = 1, v1 = 0; + + while (n > 0) { + if ((n & 1) == 1) { + long t0 = (m00 * v0 + m01 * v1) % MOD; + long t1 = (m10 * v0 + m11 * v1) % MOD; + v0 = t0; + v1 = t1; + } + long a = (m00 * m00 + m01 * m10) % MOD; + long b = (m00 * m01 + m01 * m11) % MOD; + long c = (m10 * m00 + m11 * m10) % MOD; + long d = (m10 * m01 + m11 * m11) % MOD; + m00 = a; m01 = b; + m10 = c; m11 = d; + + n >>= 1; + } + return (int) v1; + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + List inputs = new ArrayList<>(); + String line; + + while ((line = br.readLine()) != null) { + line = line.trim(); + if (!line.isEmpty()) { + inputs.add(Long.parseLong(line)); + } + } + if (!inputs.isEmpty()) { + inputs.remove(inputs.size() - 1); + } + + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + for (long n : inputs) { + bw.write(fibo(n) + "\n"); + } + bw.flush(); + bw.close(); + br.close(); + } +} \ No newline at end of file