[파이썬] 9658 돌 게임 4, 9660 돌 게임 6 // 9658 print('SK' if [1, 0, 1, 0, 1, 1, 1][(int(input())) % 7] else 'CY') // 9660 print('SK' if [1, 0, 1, 1, 1, 1, 0][(int(input()) - 1) % 7] else 'CY') Algorithm/boj 2022.09.23
[파이썬] 9657 돌 게임 3 n = int(input()) dp = [0] * 1001 dp[1] = dp[3] = dp[4] = 1 for i in range(5, n + 1): if not min(dp[i - 1], dp[i - 3], dp[i - 4]): dp[i] = 1 print('SK' if dp[n] else 'CY') dp, 게임이론 Algorithm/boj 2022.09.22
[파이썬] 9655 돌 게임, 9656 돌 게임 2, 9659 돌 게임 5 // 9655, 9659 print('SK' if int(input()) % 2 else 'CY') // 9656 print('CY' if int(input()) % 2 else 'SK') 게임이론 Algorithm/boj 2022.09.22
[파이썬] 2170 선 긋기 import sys input = sys.stdin.readline n = int(input()) li = sorted([tuple(map(int, input().split())) for _ in range(n)]) check = [list(li[0])] for i in range(1, n): if check[-1][1] >= li[i][0]: check[-1][1] = max(check[-1][1], li[i][1]) else: check.append(list(li[i])) ans = 0 for c in check: ans += c[1] - c[0] print(ans) 튜플이 리스트보다 속도가 빠름 Algorithm/boj 2022.09.21
[파이썬] 23749 카드컨트롤 from collections import deque n = int(input()) li = list(map(lambda x: 1 if x == 'O' else 0, input().split())) def win(li): return True if sum([li[2 * i] - li[2 * i + 1] for i in range(n)]) > 0 else False q = deque([[li, 0]]) while q: cur, count = q.popleft() if win(cur): print(count) break for i in range(count + 1, 2 * n): temp = [cur[i]] + cur[:i] + cur[i + 1:] q.append([temp, count + 1]) bfs,.. Algorithm/boj 2022.09.16
[파이썬] 3649 로봇 프로젝트 import sys input = sys.stdin.readline while True: try: x, n = int(input().rstrip()) * 10000000, int(input().rstrip()) li = sorted([int(input().rstrip()) for _ in range(n)]) left, right, check = 0, n - 1, 1 while left < right: s = li[left] + li[right] if s == x: print('yes', li[left], li[right]) check = 0 break elif s < x: left += 1 else: right -= 1 if check: print('danger') except: break 투포인터 Algorithm/boj 2022.09.16
[파이썬] 1072 게임 x, y = map(int, input().split()) rate = (y * 100) // x left, right = 1, x ans = -1 while left Algorithm/boj 2022.09.15
징검다리 건너기 ( Level 3, Python, 2019 카카오 개발자 겨울 인턴십 ) def solution(stones, k): left, right = 1, 200000000 while left = k: right = mid - 1 else: left = mid + 1 return left 이분탐색 Algorithm/programmers 2022.09.15
자물쇠와 열쇠 ( Level 3, Python, 2020 Kakao Blind Recruitment ) def rotate(board): board = zip(*board[::-1]) return [list(b) for b in board] def solution(key, lock): n, m = len(key), len(lock) zero = sum(lock, []).count(0) lock = [[0] * 3 * m for _ in range(m)] +\ [[0] * m + lock[i] + [0] * m for i in range(m)] +\ [[0] * 3 * m for _ in range(m)] for _ in range(4): key = rotate(key) for i in range(3 * m - n): for j in range(3 * m - n): temp, count = 0, 0 for .. Algorithm/programmers 2022.09.15
[파이썬] 1322 X와 K x, k = map(int, input().split()) bx, bk = list('0' * 100 + bin(x)[2:]), bin(k)[2:] ans = '' n, m = len(bx) - 1, len(bk) - 1 while m >= 0: if bx[n] == '0': ans = bk[m] + ans m -= 1 else: ans = '0' + ans n -= 1 print(int(ans, 2)) 비트연산문젠데 다르게 풀었음.. Algorithm/boj 2022.09.12