From a7fef4bfa3f76e35cfc09c1ef8869c86d42efb04 Mon Sep 17 00:00:00 2001 From: jibin86 Date: Wed, 15 Nov 2023 20:26:28 +0900 Subject: [PATCH 1/3] 20231115_JibinSong --- .../JibinSong/12015.py" | 25 ++++++++++++++++++ .../JibinSong/2805.py" | 26 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 "Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/12015.py" create mode 100644 "Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/2805.py" diff --git "a/Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/12015.py" "b/Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/12015.py" new file mode 100644 index 0000000..abbf94f --- /dev/null +++ "b/Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/12015.py" @@ -0,0 +1,25 @@ +def get_idx(arr, key): # key보다 크지만 가장 작은 값의 위치 + min_v = 0 + max_v = len(arr) - 1 + while True: + if min_v > max_v: + return min_v + mid = (min_v + max_v) // 2 + if arr[mid] < key: + min_v = mid + 1 + else: + max_v = mid - 1 + + +n = int(input()) # 10 20 30 15 20 25 50 45 55 60 +array = list(map(int, input().split())) +result = [array[0]] + +for i in array: + if i > result[-1]: + result.append(i) + else: + idx = get_idx(result, i) + result[idx] = i + +print(len(result)) \ No newline at end of file diff --git "a/Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/2805.py" "b/Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/2805.py" new file mode 100644 index 0000000..1e032e1 --- /dev/null +++ "b/Baekjoon/\354\235\264\353\266\204 \355\203\220\354\203\211/JibinSong/2805.py" @@ -0,0 +1,26 @@ +n, m = map(int, input().split()) + +arr = list(map(int, input().split())) + +min_h = max(arr) - m # 절단기 높이의 최솟값 +max_h = max(arr) # 절단기 높이의 최댓값 + +def count_length(mid): + cnt = 0 + for i in arr: + if i > mid: + cnt += i - mid + return cnt + +while True: + print(f"min: {min_h}, max: {max_h}, mid: {(min_h + max_h) // 2}") + if min_h > max_h: + print(max_h) + break + mid = (min_h + max_h) // 2 + cnt = count_length(mid) + print(f"cnt: {cnt}") + if cnt >= m: + min_h = mid + 1 + else: + max_h = mid - 1 \ No newline at end of file From 59bbb15eb34d67809ab609f4ac417028b1414190 Mon Sep 17 00:00:00 2001 From: jibin86 Date: Wed, 29 Nov 2023 21:18:54 +0900 Subject: [PATCH 2/3] 20231129 --- .../JibinSong/1012.py" | 48 +++++++++++++++++++ .../JibinSong/2667.py" | 44 +++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 "Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/1012.py" create mode 100644 "Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" diff --git "a/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/1012.py" "b/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/1012.py" new file mode 100644 index 0000000..aca70f5 --- /dev/null +++ "b/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/1012.py" @@ -0,0 +1,48 @@ +def dfs(x, y): + # 현재 위치 방문 처리 + visited[x][y] = 1 + # 동서남북으로 이동 + for i in range(4): + next_x = x + dx[i] + next_y = y + dy[i] + # 경계를 넘어가는지 배추가 있는지 확인 + # print("next_x", next_x, "next_y", next_y) + if (0 <= next_x <= n - 1) and ( + 0 <= next_y <= + m - 1) and arr[next_x][next_y] and not visited[next_x][next_y]: + dfs(next_x, next_y) # 인접한 배추 방문 기록 남기기 + return + + +# 동 서 남 북 +dx = [1, -1, 0, 0] +dy = [0, 0, -1, 1] + +t = int(input()) +for i in range(t): + # m: 가로, n: 세로, k: 배추 개수 + m, n, k = map(int, input().split()) + # 배추밭 + arr = [[0 for _ in range(m)] for _ in range(n)] + # 방문 기록 + visited = [[0 for _ in range(m)] for _ in range(n)] + # 배추밭에 배추 기록 + for _ in range(k): + a, b = map(int, input().split()) + arr[b][a] = 1 + # print(arr) + # print(visited) + cnt = 0 # 지렁이 수 + # 0,0 부터 시작해서 인접한 배추로 연결된 배추 그룹이 몇 개인지 확인 + for i in range(n): + for j in range(m): + # 배추 있는지, 방문한 적 있는지 확인 + if arr[i][j] and (not visited[i][j]): + # 배추 있고, 방문한 적 없으면 지렁이 추가 + cnt += 1 + # print(f"i{i}, j{j}, cnt{cnt}") + # dfs로 인접한 배추들 방문 처리하기 + dfs(i, j) + # print(visited) + + print(cnt) diff --git "a/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" "b/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" new file mode 100644 index 0000000..e049dbc --- /dev/null +++ "b/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" @@ -0,0 +1,44 @@ +def dfs(x, y): + # 방문 기록 + visited[x][y] = 1 + # 동서남북 확인 + for i in range(4): + next_x = x + dx[i] + next_y = y + dy[i] + # 경계를 넘지 않는지, 배추가 있는지 확인 + # print("x, y", next_x, next_y) + if 0 <= next_x <= n - 1 and 0 <= next_y <= n - 1 and arr[next_x][ + next_y] and not visited[next_x][next_y]: + num_home[-1] += 1 + dfs(next_x, next_y) + + return + + +dx = [0, 0, 1, -1] +dy = [1, -1, 0, 0] +n = int(input()) +# 지도 +arr = [list(map(int, list(input()))) for _ in range(n)] +visited = [[0 for _ in range(n)] for _ in range(n)] +# print("visited", visited) +# 단지 수 +cnt = 0 +# 집 개수 리스트 +num_home = [] + +# 지도 0,0부터 순회하며 연결된 집 개수 세기 +for i in range(n): + for j in range(n): + # 집이 있고, 이전에 방문한 적이 없으면, + if (not visited[i][j]) and arr[i][j]: + # 단지 개수 세기 + cnt += 1 + num_home.append(1) + # print(f"i:{i}, j:{j}, num_home", num_home) + dfs(i, j) + +print(cnt) +num_home.sort() +for i in num_home: + print(i) From 24bd365b6eefdb545f68dd0aca2fde4012e43489 Mon Sep 17 00:00:00 2001 From: jibin86 <89712324+jibin86@users.noreply.github.com> Date: Wed, 29 Nov 2023 21:52:53 +0900 Subject: [PATCH 3/3] Update 2667.py --- .../JibinSong/2667.py" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" "b/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" index e049dbc..d81a63e 100644 --- "a/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" +++ "b/Baekjoon/\352\267\270\353\236\230\355\224\204\354\231\200 \354\210\234\355\232\214/JibinSong/2667.py" @@ -5,7 +5,7 @@ def dfs(x, y): for i in range(4): next_x = x + dx[i] next_y = y + dy[i] - # 경계를 넘지 않는지, 배추가 있는지 확인 + # 경계를 넘지 않는지, 집이 있는지 확인 # print("x, y", next_x, next_y) if 0 <= next_x <= n - 1 and 0 <= next_y <= n - 1 and arr[next_x][ next_y] and not visited[next_x][next_y]: