백준 / 1309 / 동물원 / python
·
Coding Test/Baekjoon
문제 : https://www.acmicpc.net/problem/1309 문제 나의 풀이N = int(input())dp = [[0] * 3 for _ in range(N + 1)]for i in range(3): dp[1][i] = 1for i in range(2, N + 1): if dp[i - 1][0]: dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][2]) % 9901 if dp[i - 1][1]: dp[i][1] = dp[i - 1][0] + dp[i - 1][2] % 9901 if dp[i - 1][2]: dp[i][2] = dp[i - 1][0] + dp[i - 1][1] % 9901..
백준 / 1074 / Z / python
·
Coding Test/Baekjoon
문제: https://www.acmicpc.net/problem/1074 코드def z(N, r, c): if N == 0: return 0 half = 2 ** (N - 1) block_size = half * half if r = half: return block_size + z(N - 1, r, c - half) elif r >= half and c 배열을 계속 4개의 사분면으로 나누며 r,c가 어느 사분면에 속하는지 확인하고, 그 사분면 이전에 이미 방문한 칸 수를 누적해서 더해 나간다. 해당 사분면 내부의 상대 좌표로 이동해 다시 같은 방식으로 계산하며, 결국 N이 0이 되면 더 나눌 수 없으므로 0을 반환해 재귀가 끝난다. 즉, “지금 ..
백준 / 9466번 / 텀 프로젝트 / python 파이썬
·
Coding Test/Baekjoon
문제 : https://www.acmicpc.net/problem/9466 나의 풀이import syssys.setrecursionlimit(10**7)input = sys.stdin.readline# 사이클 생성 유무 확인def dfs(now): global cnt visited[now] = 1 nxt = numbers[now] if not visited[nxt]: dfs(nxt) else: # 이미 방문했는데 탐색이 끝나지 않았다면 # 현재 경로에 있는 노드를 다시 봤다는 의미 -> 사이클 발생 if not finished[nxt]: cur = nxt while cur != now..
Programmers / 비밀 코드 해독 / Python
·
Coding Test/Programmers
문제: https://school.programmers.co.kr/learn/courses/30/lessons/388352 코드from itertools import combinationsdef solution(n, q, ans): count = 0 num = list(range(1, n + 1)) correct = list(combinations(num, 5)) for cor in correct: is_correct = True for code, answer in zip(q, ans): if len(set(cor) & set(code)) != answer: is_correct = False ..
백준 / 7569번 / 토마토 / python 파이썬
·
Coding Test/Baekjoon
문제 : https://www.acmicpc.net/problem/7569 나의 풀이import sysfrom collections import dequeinput = sys.stdin.readlineM, N, H = map(int, input().split())boxes = [[list(map(int, input().split())) for _ in range(N)] for _ in range(H)]def bfs(): q = deque() # 처음부터 익은 토마토 큐에 추가 for tomato in tomatoes: q.append(tomato) dz = [1, -1, 0, 0, 0, 0] dy = [0, 0, 1, -1, 0, 0] dx = [0, 0,..
백준 / 3190번 / 뱀 / python 파이썬
·
Coding Test/Baekjoon
문제 : https://www.acmicpc.net/problem/3190 나의 풀이import sysfrom collections import dequeinput = sys.stdin.readlineN = int(input())K = int(input())apples = [list(map(int, input().split())) for _ in range(K)]L = int(input())rotation = [list(input().split()) for _ in range(L)]board = [[0] * N for _ in range(N)]for a, b in apples: board[a-1][b-1] = 1def bfs(start): dx = [0, 1, 0, -1] dy = [..
Programmers / 하노이의 탑 / python 파이썬
·
Coding Test/Programmers
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/12946 코드def solution(n): result = [] def hanoi(n, start, end, temp): if n == 1: result.append([start, end]) return hanoi(n-1, start, temp, end) result.append([start, end]) hanoi(n-1, temp, end, start) hanoi(n, 1, 3, 2) return result
백준 / 15683번 / 감시 / python 파이썬
·
Coding Test/Baekjoon
문제 : https://www.acmicpc.net/problem/15683 나의 풀이import sysinput = sys.stdin.readlinen, m = map(int, input().split())Map = [list(map(int, input().split())) for _ in range(n)]dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]cctv_type = { 1: [[0], [1], [2], [3]], # 상, 하, 좌, 우 2: [[0, 1], [2, 3]], # 상+하, 좌+우 3: [[0, 3], [3, 1], [1, 2], [2, 0]], # 상+우, 우+하, 하+좌, 좌+..