์ฝ”๋”ฉํ…Œ์ŠคํŠธ๐Ÿ’ก

๋ฌธ์ œํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค N-Queenhttps://school.programmers.co.kr/learn/courses/30/lessons/12952' ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr ์ฝ”๋“œdef solution(n): global answer v1 = [0 for _ in range(n)] # ์—ด v2 = [0 for _ in range(n * 2)] # ๋Œ€๊ฐ์„  ์ƒ๋ฐฉ v3 = [0 for _ in range(n * 2)] # ๋Œ€๊ฐ์„  ํ•˜๋ฐฉ answer = 0 def dfs(row): global answ..
๋ฌธ์ œํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์†Œ์ˆ˜์ฐพ๊ธฐhttps://school.programmers.co.kr/learn/courses/30/lessons/42839 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.programmers.co.kr  ์ฝ”๋“œimport itertoolsdef sosu(num): if num == 0 or num == 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return Truedef solution(n): answe..
๋ฌธ์ œ๋ฐฑ์ค€  ๋‰ด์Šค ์ „ํ•˜๊ธฐ https://www.acmicpc.net/problem/1135 ์ฝ”๋“œn = int(input())parent_list = list(map(int, input().split()))child_list = [list() for _ in range(n)]for child in range(1, n) : parent = parent_list[child] child_list[parent].append(child)def dfs(node) : if not child_list[node] : return 0 result = list() for child in child_list[node] : result.append(dfs(child)) result.sort( reverse =..
๋ฌธ์ œ๋ฐฑ์ค€ 1927 ์ตœ์†Œ ํž™ https://www.acmicpc.net/problem/1927๋ฐฑ์ค€ 11279 ์ตœ๋Œ€ ํž™ https://www.acmicpc.net/problem/11279 ์ตœ์†Œ ํž™ ์ฒ˜์Œ ์ฝ”๋“œ (์‹œ๊ฐ„์ดˆ๊ณผ)๋ฐฐ์—ด์—์„œ min()์„ ์ด์šฉํ•˜์—ฌ ์ตœ์†Œ๊ฐ’์„ ์ฐพ์•˜๋‹ค.n = int(input())x = []for _ in range(n):    num = int(input())    if num == 0:        if x:            print(min(x))            x.remove(min(x))        else:            print(0)    else:        x.append(num) ์ตœ์†Œ ํž™ ์ฝ”๋“œimport sysimport heapqn = int(input()..
๋ฌธ์ œhttps://www.acmicpc.net/problem/14888 ์ฝ”๋“œn = int(input())num = list(map(int, input().split()))operation = list(map(int, input().split())) # +, -, *, /maxi = -1e9mini = 1e9def dfs(idx, result, plus, minus, multiply, divide): global maxi, mini if idx == n: maxi = max(result, maxi) mini = min(result, mini) return if plus > 0: dfs(idx + 1, result + num[idx], pl..
๋ฌธ์ œhttps://www.acmicpc.net/problem/1012 ์ฝ”๋“œfrom collections import dequeT = int(input())for _ in range(T): n, m, k = map(int, input().split()) # ๊ฐ€๋กœ, ์„ธ๋กœ, ๋ฐฐ์ถ”๊ฐœ์ˆ˜ field = [[0 for _ in range(n)] for _ in range(m)] visit = [[False for _ in range(n)] for _ in range(m)] answer = 0 # ๋ฐฐ์ถ” ์ง€๋„ ๊ทธ๋ฆฌ๊ธฐ for l in range(k): x, y = map(int, input().split()) field[y][x] = 1 for i in..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 1338. Reduce Array Size To The Halfhttps://leetcode.com/problems/reduce-array-size-to-the-half/description/ ์ฝ”๋“œclass Solution(object): def minSetSize(self, arr): answer = 0 count_num = {} for num in arr: if num not in count_num.keys(): count_num[num] = 1 else: count_num[num] += 1 values = sorted(list(..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 1845. Seat Reservation Managerhttps://leetcode.com/problems/seat-reservation-manager/  ์ฝ”๋“œimport heapqclass SeatManager: def __init__(self, n): self.can_reserve = list(range(1, n + 1)) heapq.heapify(self.can_reserve) def reserve(self): return heapq.heappop(self.can_reserve) def unreserve(self, seatNumber): heapq.heappush(self.can_reserve, seatNumber)..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 921. Minimum Add to Make Parentheses Valishttps://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ ์ฝ”๋“œclass Solution(object): def minAddToMakeValid(self, s): s = deque(s) stack = [] item = s.popleft() stack.append(item) while s: item = s.popleft() if not stack: stack.append(item) else: ..
๋ฌธ์ œ2390. Removing Stars From a String https://leetcode.com/problems/removing-stars-from-a-string/ ์ฝ”๋“œclass Solution(object): def removeStars(self, s): s = list(s) while '*' in s: for i in range(len(s)-1): if s[i + 1] == '*': s.pop(i+1) s.pop(i) break return ''.join(s) ํ’€์ดs = list(s)๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์€ ๋ฌธ์ž..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 1823. Find the Winner of the Circular Gamehttps://leetcode.com/problems/find-the-winner-of-the-circular-game/solutions/ ์ฝ”๋“œclass Solution: def findTheWinner(self, n: int, k: int) -> int: circle = [i for i in range(1, n+1)] count = 1 turn = 0 while len(circle) != 1: if count == k: circle.pop(turn) count = 1 ..
๋ฌธ์ œ๋ฐฑ์ค€ ๊ฑธ๊ทธ๋ฃน ๋งˆ์Šคํ„ฐ ์ค€์„์ด https://www.acmicpc.net/problem/16165 ์ฝ”๋“œn, m = map(int, input().split()) # ๊ฑธ๊ทธ๋ฃน์˜ ์ˆ˜, ๋งžํ˜€์•ผ ํ•  ๋ฌธ์ œ์˜ ์ˆ˜idol_dic = {}for _ in range(n): team_name = input() team_member_num = int(input()) team_member = [] for _ in range(team_member_num): team_member.append(input()) idol_dic[team_name] = team_memberfor _ in range(m): quiz = input() quiz_type = int(input()) ..
๋•ก๋•ก๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป
'์ฝ”๋”ฉํ…Œ์ŠคํŠธ๐Ÿ’ก' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก