๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

TIL51

[TIL] Pintos Project1 - Threads ์ •๋ฆฌ โ€ป git book ๊ธฐ์ค€์œผ๋กœ ์ดํ•ดํ•œ ๋‚ด์šฉ ์ •๋ฆฌ โ€ป 0. ๊ฐœ๋… ๋ฐ ์ฝ”๋“œ ์ •๋ฆฌ 1. thread CPU ์ด์šฉ์˜ ๊ธฐ๋ณธ ๋‹จ์œ„, ๋™์ผ ํ”„๋กœ์„ธ์Šค์˜ ์Šค๋ ˆ๋“œ๋“ค์€ ์ฝ”๋“œ ์˜์—ญ, ๋ฐ์ดํ„ฐ ์˜์—ญ, ์šด์˜์ฒด์ œ ์ž์›๋“ค์„ ๊ณต์œ  ํ•€ํ† ์Šค์—์„œ๋Š” ๋‹จ์ผ ์Šค๋ ˆ๋“œ ํ”„๋กœ์„ธ์Šค(Single thread process)๋ฅผ ๊ตฌํ˜„! ๊ทธ๋Ÿฌ๋ฏ€๋กœ ํ”„๋กœ์„ธ์Šค์˜ ์ƒํƒœ๋ณ€ํ™”๊ฐ€ ์Šค๋ ˆ๋“œ์˜ ์ƒํƒœ๋ณ€ํ™”์™€ ๋™์ผํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ณ  ๊ตฌํ˜„ํ•จ ์ด๋Ÿฌํ•œ ๋ฉ€ํ‹ฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ๋ชฉ์ ์€ CPU ์‚ฌ์šฉ๋ฅ ์„ ์ตœ๋Œ€ํ™”ํ•˜๊ธฐ ์œ„ํ•จ์ด๋ฉฐ, ์–ด๋–ค ํ”„๋กœ์„ธ์Šค๋“  ํ•ญ์ƒ ์‹คํ–‰ ์ค‘์ด๊ฒŒ ํ•œ๋‹ค. time sharing(์‹œ๋ถ„ํ•  ์‹œ์Šคํ…œ) : ์—ฌ๋Ÿฌ ํ”„๋กœ์„ธ์Šค ์‚ฌ์ด์—์„œ CPU๋ฅผ ์ž์ฃผ ์ „ํ™˜ํ•จ์œผ๋กœ์จ ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž ํ”„๋กœ๊ทธ๋žจ์ด ์ˆ˜ํ–‰๋˜๋Š” ๋™์•ˆ ๊ฐ ํ”„๋กœ๊ทธ๋žจ๊ณผ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค. Process scheduler : CPU์—์„œ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์„ ์œ„ํ•ด ์‹ค.. 2023. 6. 28.
[TIL] Pintos - ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ จ ๊ฐœ๋… ๊ณต๋ถ€2 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 10026๋ฒˆ - ์ ๋ก์ƒ‰์•ฝ import sys from collections import deque N = int(sys.stdin.readline()) pic = [list(sys.stdin.readline().strip()) for _ in range(N)] dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def bfs(x, y) : queue = deque() queue.append((x, y)) visited[x][y] = True while queue : cx, cy = queue.popleft() for i in range(4) : nx, ny = cx + dx[i], cy + dy[i] if nx >= 0 and nx = 0 .. 2023. 6. 15.
[TIL] Pintos - ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ จ ๊ฐœ๋… ๊ณต๋ถ€1 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 2023๋ฒˆ - ์‹ ๊ธฐํ•œ ์†Œ์ˆ˜ import sys N = int(sys.stdin.readline()) result = [] #์†Œ์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•˜๋Š” ํ•จ์ˆ˜ def isPrime(n) : for i in range(2, int(n**(1/2))+1) : if n % i == 0 : return False return True #๋ฐฑํŠธ๋ž˜ํ‚น ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ ํƒ์ƒ‰ def dfs(depth, n) : if depth == N : if isPrime(n) : result.append(n) return for i in range(10) : nn = n*10 + i if isPrime(nn) : dfs(depth+1, n*10+i) prime = [2, 3, 5, 7] for p in prime : df.. 2023. 6. 14.
[TIL] 1377๋ฒˆ - ๋ฒ„๋ธ” ์ •๋ ฌ 1. 1377๋ฒˆ - ๋ฒ„๋ธ” ์ •๋ ฌ import sys N = int(sys.stdin.readline()) array = [[int(sys.stdin.readline()), i] for i in range(N)] array.sort() max = -sys.maxsize for i in range(N) : t = array[i][1] - i if max < t : max = t print(max+1) ์ด ๋ฌธ์ œ๋Š” ๋ฒ„๋ธ” ์ •๋ ฌ์‹œ ์™„๋ฃŒ๋˜๋Š” ๋ฐ˜๋ณต ํšŸ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ์ฃผ์–ด์ง„ c++ ์ฝ”๋“œ๋กœ๋„ ๋‹ต์€ ๊ตฌํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค. ์ฆ‰, ์ด์ค‘ ๋ฐ˜๋ณต๋ฌธ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์œ„์˜ ๊ทธ๋ฆผ์€ ๋ฒ„๋ธ” ์ •๋ ฌ ๊ณผ์ •์„ ์จ๋ณธ ๊ฒƒ์ด๋‹ค. ๋ฒ„๋ธ” ์ •๋ ฌ์€ ๋งจ ๋’ค์—์„œ ๋ถ€ํ„ฐ ํฐ ๊ฐ’์ด ๋จผ์ € ์ •๋ ฌ๋œ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์ •๋ ฌ๋˜์ง€ ์•Š์€ ๊ฐ’ ์ค‘ ๊ฐ€์žฅ ํฐ ๊ฐ’.. 2023. 6. 7.
[TIL] OS - System Call 1. ์šด์˜์ฒด์ œ ์„œ๋น„์Šค(Operating System Service) ์‚ฌ์šฉ์ž์—๊ฒŒ ๋„์›€์„ ์ฃผ๊ธฐ ์œ„ํ•œ ๊ธฐ๋Šฅ ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค(User Interface) GUI(๊ทธ๋ž˜ํ”ฝ ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค) CLI(๋ช…๋ น์–ด ๋ผ์ธ ์ธํ„ฐํŽ˜์ด์Šค) Batch Interface(์ผ๊ด„์ฒ˜๋ฆฌ ์ธํ„ฐํŽ˜์ด์Šค) https://ko.wikipedia.org/wiki/์‚ฌ์šฉ์ž_์ธํ„ฐํŽ˜์ด์Šค ํ”„๋กœ๊ทธ๋žจ ์ˆ˜ํ–‰(Program Execution) ํ”„๋กœ๊ทธ๋žจ์„ ๋ฉ”๋ชจ๋ฆฌ์— ์ ์žฌ(load)ํ•ด ๊ตฌ๋™(Run)ํ•˜๊ณ  ์‹คํ–‰(Execute)ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ •์ƒ์ ์ด๋“  ๋น„์ •์ƒ์ ์ด๋“  ์‹คํ–‰์„ ๋๋‚ผ ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ž…์ถœ๋ ฅ ์—ฐ์‚ฐ(I/O Operation) ์ˆ˜ํ–‰ ์ค‘์ธ ํ”„๋กœ๊ทธ๋žจ์€ ์ž…์ถœ๋ ฅ์„ ์š”๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. ํšจ์œจ๊ณผ ๋ณดํ˜ธ๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉ์ž๋“ค์ด ์ง์ ‘ ์ œ์–ด๋ฅผ ํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์šด์˜์ฒด์ œ๊ฐ€ ์ˆ˜๋‹จ ์ œ๊ณต ํ†ต์‹ (Co.. 2023. 6. 7.
[TIL] OS ์šฉ์–ด ์ •๋ฆฌ 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 1049๋ฒˆ - ๊ธฐํƒ€์ค„ import sys N, M = map(int, sys.stdin.readline().split()) min_six = sys.maxsize min_one = sys.maxsize # ๊ฐ€์žฅ ์ž‘์€ ๊ฐ€๊ฒฉ ๊ตฌํ•˜๊ธฐ for _ in range(M) : six, one = map(int, sys.stdin.readline().split()) if min_six > six : min_six = six if min_one > one : min_one = one count = N // 6 + 1 #6์˜ ๋ฐฐ์ˆ˜๊ฐ€ ๋˜๋„๋กํ•˜๋ฉด์„œ ์ ์–ด๋„ N๋ณด๋‹ค ํฐ ๋ชซ ๊ตฌํ•˜๊ธฐ a = min_six * count # ๋ฌถ์Œ์œผ๋กœ๋งŒ ๊ตฌ๋งคํ•  ๊ฒฝ์šฐ b = min_one * N #๋‚ฑ๊ฐœ๋กœ๋งŒ ๊ตฌ๋งคํ•  ๊ฒฝ์šฐ c = m.. 2023. 5. 26.
[TIL] Thread ๊ฐœ๋… ์ •๋ฆฌ 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 26069๋ฒˆ - ๋ถ™์ž„์„ฑ ์ข‹์€ ์ด์ด์ด import sys N = int(sys.stdin.readline()) dance = {'ChongChong' : 1} for _ in range(N) : a, b = sys.stdin.readline().split() # ๋‘ ์‚ฌ๋žŒ ์ค‘ ํ•œ ์‚ฌ๋žŒ๋งŒ ์ถค์„ ์ถ”๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ๋ฅผ ๋‚˜๋ˆ  dance ๋ชฉ๋ก์— ์ €์žฅ if a in dance and b not in dance: dance[b] = 1 elif a not in dance and b in dance : dance[a] = 1 print(len(dance)) ๊ฐ€๋ณ๊ฒŒ Dictionary๋ฅผ ์ด์šฉํ•ด ํ‘ผ ๋ฌธ์ œ 2. Thread ์–ด๋– ํ•œ ํ”„๋กœ๊ทธ๋žจ ๋‚ด์—์„œ, ํŠนํžˆ ํ”„๋กœ์„ธ์Šค ๋‚ด์—์„œ ์‹คํ–‰๋˜๋Š” ํ๋ฆ„์˜ ๋‹จ์œ„ ํ”„๋กœ์„ธ์Šค์˜ c.. 2023. 5. 25.
[TIL] 7์ฃผ์ฐจ - ๋„˜๊ฒผ๋˜ ๋ถ€๋ถ„ ๋™๋ฃŒํ•™์Šต ์ •๋ฆฌ 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 2559๋ฒˆ - ์ˆ˜์—ด - 2023.05.24 import sys N, K = map(int, sys.stdin.readline().split()) nums = list(map(int, sys.stdin.readline().split())) result = sum(nums[:K]) # ๊ตฌํ•ด์•ผํ•  ๊ฐ’ curr = result # ํ˜„์žฌ 0๋ถ€ํ„ฐ K-1๊นŒ์ง€ ์—ฐ์†๋œ ๊ฐ’์˜ ํ•ฉ for i in range(K, N) : curr = curr - nums[i-K] + nums[i] # ๋งจ์•ž์˜ ๊ฐ’์€ ๋นผ๊ณ  ๋’ค์— ๊ฐ’ ์ถ”๊ฐ€(์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ) if curr > result : result = curr print(result) ์ „์— ๊ณต๋ถ€ํ–ˆ๋˜ ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ‘ผ ๋ฌธ์ œ ์š”์ฆ˜ ์ ์  ํ’€์ˆ˜๋ก ์–ด๋–ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์„.. 2023. 5. 24.
[TIL] Proxy ๊ฐœ๋… ์ •๋ฆฌ 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 2108๋ฒˆ - ํ†ต๊ณ„ํ•™ import sys import math N = int(sys.stdin.readline().strip()) nums = {} # ์ž…๋ ฅ๋ฐ›์€ ์ˆ˜๋“ค์˜ ๋“ฑ์žฅ ํšŸ์ˆ˜ lst = [0] * N # ์ž…๋ ฅ๋ฐ›์€ ์ˆ˜๋“ค sum = 0 for i in range(N) : num = int(sys.stdin.readline().strip()) if num in nums : nums[num] += 1 else : nums[num] = 1 lst[i] = num sum += num lst.sort() nums = dict(sorted(nums.items())) nums = sorted(nums.items(), key= lambda x : -x[1]) print(round(sum/N).. 2023. 5. 24.
[TIL] CSAPP 11์žฅ ๊ณต๋ถ€4 - tiny ์„œ๋ฒ„ ์ •๋ฆฌ 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 20920๋ฒˆ - ์˜๋‹จ์–ด ์•”๊ธฐ๋Š” ๊ดด๋กœ์›Œ import sys N, M = map(int, sys.stdin.readline().split()) words = {} # key = ์˜์–ด๋‹จ์–ด / value = ์˜์–ด๋‹จ์–ด ์ž…๋ ฅ ํšŸ์ˆ˜ for _ in range(N) : w = sys.stdin.readline().strip() if len(w) >= M : if w in words : words[w] += 1 else : words[w] = 1 # ๋‹จ์–ด๋ฅผ ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ •๋ ฌ words = dict(sorted(words.items())) # ๋‹จ์–ด๋ฅผ ์ž…๋ ฅ ํšŸ์ˆ˜๊ฐ€ ๋งŽ์€ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋˜ ๊ฐ™์œผ๋ฉด ๊ธธ์ด๊ฐ€ ๊ธด ๊ฒƒ๋ถ€ํ„ฐ ์ •๋ ฌ words = dict(sorted(words.items(), key=lambda .. 2023. 5. 22.
[TIL] CSAPP 11์žฅ ๊ณต๋ถ€3 - ์›น ์„œ๋ฒ„ 1. Web ๊ธฐ์ดˆ 1. HTTP(Hypertext Transfer Protocol) ์›น ์ƒ์—์„œ ์›น ์„œ๋ฒ„ ๋ฐ ์›น ๋ธŒ๋ผ์šฐ์ €(ํด๋ผ์ด์–ธํŠธ) ์ƒํ˜ธ ๊ฐ„์˜ ๋ฐ์ดํ„ฐ ์ „์†ก์„ ์œ„ํ•œ ์‘์šฉ(๊ณ„์ธต ํ”„๋กœํ† ์ฝœ ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ์‘์šฉ์ˆ˜์ค€ ํ”„๋กœํ† ์ฝœ๋กœ ์ฃผ๋กœ HTML ๋ฌธ์„œ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. https://ko.wikipedia.org/wiki/HTTP ์›น ์„œ๋ฒ„ ํฌํŠธ ๋ฒˆํ˜ธ : 80 ์š”์ฒญ/์‘๋‹ต(Request/Response) ํ”„๋กœํ† ์ฝœ ํด๋ผ์ด์–ธํŠธ → ์„œ๋ฒ„ : ์ฝ˜ํ…์ธ  ์š”์ฒญ ์„œ๋ฒ„ → ํด๋ผ์ด์–ธํŠธ : ์š”์ฒญ๋ฐ›์€ ์ฝ˜ํ…์ธ ๋กœ ์‘๋‹ต ๐Ÿ”— http://www.ktword.co.kr/test/view/view.php?m_temp1=4884&id=902 HTTP Method ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์›น ์„œ๋ฒ„์—๊ฒŒ ์š”์ฒญํ•˜๋Š” ๋ชฉ์  ๋ฐ ๊ทธ ์ข…๋ฅ˜๋ฅผ ์•Œ๋ฆฌ๋Š” ์ˆ˜๋‹จ GET : ๋ฆฌ.. 2023. 5. 21.
[TIL] CSAPP 11์žฅ ๊ณต๋ถ€2 - ์˜ˆ์ œ echo ์„œ๋ฒ„ 1. ์ƒ์œ„ ์ˆ˜์ค€์˜ ๋„์›€ ํ•จ์ˆ˜ 1. open_clientfd() ํด๋ผ์ด์–ธํŠธ๋Š” ์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์„œ๋ฒ„์™€ ์—ฐ๊ฒฐ์„ ์„ค์ •ํ•œ๋‹ค. 2. open_listenfd() ์„œ๋ฒ„๋Š” ์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์—ฐ๊ฒฐ ์š”์ฒญ์„ ๋ฐ›์„ ์ค€๋น„๊ฐ€ ๋œ ๋“ฃ๊ธฐ ์‹๋ณ„์ž ์ƒ์„ฑ โ–ถ setsockopt() : ์†Œ์ผ“ ์„ธ๋ถ€ ์‚ฌํ•ญ ์„ค์ • int setsockopt(int sock, int level, int optname, const void *optval, socklen_t optlen); sock : ์†Œ์ผ“ ํŒŒ์ผ ๋””์Šคํฌ๋ฆฝํ„ฐ level : ํ”„๋กœํ† ์ฝœ ๋ ˆ๋ฒจ ์ „๋‹ฌ SOL_SOCKET : ์ผ๋ฐ˜ IPPROTO_IP : IP - IPv4 IPPROTO_TCP : TCP optname : ๋ณ€๊ฒฝํ•  ์˜ต์…˜์˜ ์ด๋ฆ„ SO_REUSEADDR : ์ด๋ฏธ ์‚ฌ์šฉ์ค‘์ธ ์ฃผ์†Œ๋‚˜ ํฌํŠธ์— ๋Œ€ํ•ด์„œ๋„ ๋ฐ”์ธ.. 2023. 5. 20.
[TIL] CSAPP 11์žฅ ๊ณต๋ถ€ - ๋„คํŠธ์›Œํฌ 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 1966๋ฒˆ - ํ”„๋ฆฐํ„ฐ ํ - 2023.05.18 import sys from collections import deque testcase = int(sys.stdin.readline()) for _ in range(testcase) : N, M = map(int, sys.stdin.readline().split()) priorty = list(map(int, sys.stdin.readline().split())) queue = deque() for i in range(N) : queue.append((i, priorty[i])) # ์›๋ž˜ ์œ„์น˜์™€ ์ค‘์š”๋„๋ฅผ ๊ฐ™์ด ํ์— ๋„ฃ์–ด์ค€๋‹ค. count = 0 while queue : flag = True #True์ผ ๊ฒฝ์šฐ ์ถœ๋ ฅ ๊ฐ€๋Šฅ / Fals.. 2023. 5. 19.
[TIL] CASPP 9์žฅ ๊ณต๋ถ€5 - ๊ฐ„๋‹จํ•œ ํ• ๋‹น๊ธฐ3(segregated) 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 1359๋ฒˆ - ๋ณต๊ถŒ import sys from itertools import combinations N, M, K = map(int, sys.stdin.readline().split()) jimin = list(combinations(range(N), M)) # ์ง€๋ฏผ์ด๊ฐ€ ๋ฝ‘์„ ์ˆ˜๋“ค์˜ ์กฐํ•ฉ result = list(combinations(range(N), M)) # ๋‹น์ฒจ ๊ฒฐ๊ณผ๋“ค์˜ ์กฐํ•ฉ luck = 0 # ๋‹น์ฒจ๋œ ํšŸ์ˆ˜ ์ €์žฅ for jm in jimin : for re in result : count = 0 # ํ˜„์žฌ ์ง€๋ฏผ์ด์™€ ๊ฒฐ๊ณผ๊ฐ€ ๊ฐ™์€ ์ˆ˜์˜ ๊ฐœ์ˆ˜ for i in range(M) : for j in range(M) : if jm[i] == re[j] : count += 1 if c.. 2023. 5. 17.
[TIL] CSAPP 9์žฅ ๊ณต๋ถ€5 - segregated list(๊ฐœ๋… ๊ณต๋ถ€) 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 1057๋ฒˆ - ํ† ๋„ˆ๋จผํŠธ import sys N, kim, im = map(int, sys.stdin.readline().split()) count = 0 flag = True if N % 2 == 0 : #์ฐธ๊ฐ€์ž๊ฐ€ ํ™€์ˆ˜์ผ ๊ฒฝ์šฐ N += 1 while N > 0 : # ๋‹ค์Œ ๊ฒฝ๊ธฐ์—์„œ์˜ ๋ฒˆํ˜ธ ๊ตฌํ•˜๊ธฐ if kim % 2 == 0 and im % 2 == 0: kim //= 2 im //= 2 elif kim % 2 != 0 and im % 2 == 0: kim = (kim+1) //2 im //= 2 elif kim % 2 == 0 and im % 2 != 0: kim //= 2 im = (im+1) //2 else : kim = (kim+1) //2 im = (im+1) //2 c.. 2023. 5. 16.
[TIL] CSAPP 9์žฅ ๊ณต๋ถ€4 - ๊ฐ„๋‹จํ•œ ํ• ๋‹น๊ธฐ2(Explicit, first-fit) 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 25192๋ฒˆ - ์ธ์‚ฌ์„ฑ ๋ฐ์€ ๊ณฐ๊ณฐ์ด import sys N = int(sys.stdin.readline()) record = {} count = 0 for _ in range(N) : input = sys.stdin.readline().strip() if input == 'ENTER' : record = {} # ๋ชจ๋“  ๊ธฐ๋ก ์ดˆ๊ธฐํ™” elif input not in record : count += 1 record[input] = 1 print(count) ์•„์นจ๋งˆ๋‹ค ๊ฐ™์ด ๊ณต๋ถ€ํ•˜๋Š” ์‚ฌ๋žŒ๋“ค๋ผ๋ฆฌ ๋ฌธ์ œ๋ฅผ ํ’€๊ณ  ์žˆ๋‹ค. ์˜ค๋Š˜ ๋ฌธ์ œ๋Š” ์ข€ ๊ท€์—ฌ์› ๋‹ค. ์ €๋ฒˆ ๊ธˆ์š”์ผ์˜ ๋ฌธ์ œ ํ’€์ด์— ์ด์–ด์„œ Hash๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ’€๋ฉด ๋œ๋‹ค. 2. Explicit Free List ๋ช…์‹œ์  ๊ฐ€์šฉ ๋ฆฌ์ŠคํŠธ 1. ๋ฌต์‹œ์  ๊ฐ€์šฉ ๋ฆฌ์ŠคํŠธ.. 2023. 5. 15.
[TIL] CSAPP 9์žฅ ๊ณต๋ถ€3 - next-fit 1. ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด 1. 1107๋ฒˆ - ๋ฆฌ๋ชจ์ปจ import sys N = int(sys.stdin.readline()) #๋ชฉํ‘œ ์ฑ„๋„ M = int(sys.stdin.readline()) # ๋ง๊ฐ€์ง„ ๋ฒˆํ˜ธ ์ˆ˜ brocken = {} if M : for i in list(sys.stdin.readline().split()) : brocken[i] = 1 count = abs(100 - N) # + ๋˜๋Š” - ๋กœ๋งŒ ์›€์ง์˜€์„ ๋•Œ ํšŸ์ˆ˜ if count != 0 : # ์ด๋ฏธ ๋ชฉํ‘œ ์ฑ„๋„์ด ์•„๋‹ ๊ฒฝ์šฐ๋งŒ ๋ฐ˜๋ณต for i in range(1000001) : num = str(i) #ํ˜„์žฌ ์ฑ„๋„ ๋ฒˆํ˜ธ length = len(num) for j in range(length) : if num[j] in brocken : #์ฑ„๋„.. 2023. 5. 14.
[TIL] CSAPP 9์žฅ ๊ณต๋ถ€3 - ๊ฐ„๋‹จํ•œ ํ• ๋‹น๊ธฐ(Implicit, first-fit) 1. ์•„์นจ ๋ฌธ์ œ ํ’€์ด 1. 10026๋ฒˆ - ์ ๋ก์ƒ‰์•ฝ import sys from collections import deque N = int(sys.stdin.readline()) graph = [list(sys.stdin.readline().strip()) for _ in range(N)] color_count = 0 color_weakness = 0 dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def bfs(x, y) : #์ƒ‰์•ฝ์ด ์•„๋‹Œ ์‚ฌ๋žŒ์ด ๋ณด๋Š” ๊ตฌ์—ญ global color_count, color_weakness queue = deque() visited[x][y] = 1 queue.append((x,y)) while queue : curx, cury = queue.poplef.. 2023. 5. 14.
728x90