[Coding Test]/[백준]

    [백준] 14889: 스타트와 링크

    [백준] 14889: 스타트와 링크

    https://www.acmicpc.net/problem/14889  조합)import sysfrom itertools import combinationsdef solution(): n = int(sys.stdin.readline().strip()) graph = [ list(map(int, sys.stdin.readline().split())) for _ in range(n) ] min_diff = float('inf') player = list(range(n)) team = list(combinations(player, n //2)) for idx in range(len(team) // 2): start_team = set(team[idx]) ..

    [백준] 1158: 요세푸스 문제

    [백준] 1158: 요세푸스 문제

    1158번: 요세푸스 문제  import sysdef solution(): n, k = map(int, sys.stdin.readline().split()) circle = list(range(1, n+1)) answer = [] idx = 0 while circle: idx = (idx + k - 1) % len(circle) answer.append(circle.pop(idx)) print(f'')solution() 프로그래머스: 모의고사카드2

    [백준] 3085: 사탕 게임

    https://www.acmicpc.net/problem/3085 3085번: 사탕 게임예제 3의 경우 4번 행의 Y와 C를 바꾸면 사탕 네 개를 먹을 수 있다.www.acmicpc.net import sysdef solution(): n = int(sys.stdin.readline()) board = [ list(sys.stdin.readline().strip()) for _ in range(n) ] max_length = 1 def max_candy_count(board, n): max_count = 1 for i in range(n): row_count, col_count = 1, 1 for j in range(n..

    [백준] 2309: 일곱 난쟁이

    [백준] 2309: 일곱 난쟁이

    https://www.acmicpc.net/problem/2309 2309번: 일곱 난쟁이아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.www.acmicpc.net  import sysfrom itertools import combinationsdef solution(): arr = [] for i in range(9): arr.append(int(sys.stdin.readline())) for com in combinations(arr, 7): if sum(com) == 100: for height in so..

    [백준] 4963: 섬의 개수

    [백준] 4963: 섬의 개수

    https://www.acmicpc.net/problem/4963 import syssys.setrecursionlimit(10**4)while True: w, h = map(int, sys.stdin.readline().split()) if w == 0 and h == 0: break graph = [ ] for i in range(h): graph.append(list(map(int, sys.stdin.readline().split()))) visited = [ [0]*w for _ in range(h) ] dx = [ 0, 0, -1, 1, 1, 1, -1, -1 ] dy = [ -1, 1, 0, 0, 1, -1, -1, 1 ] ..

    [백준] 11724: 연결 요소의 개수

    [백준] 11724: 연결 요소의 개수

    11724번: 연결 요소의 개수 import sysn, m = map(int, input().split())graph = [ [] for _ in range(n+1) ]for _ in range(m): a, b = map(int, sys.stdin.readline().split()) graph[a].append(b) graph[b].append(a)cnt = 0visit = [False] * (n+1)def dfs(v): visit[v] = True for i in graph[v]: if not visit[i]: dfs(i)for i in range(1, n+1): if not visit[i]: dfs(i) cnt ..