본문 바로가기

분류 전체보기263

[백준] 17136번 - 색종이 붙이기 (파이썬) # 색종이 붙이기 import sys import copy input = sys.stdin.readline MAX = sys.maxsize N = 10 arr = [] length_one = 0 for i in range(N): arr.append(list(map(int, input().split()))) for j in range(N): if arr[i][j] == 1: length_one += 1 paper = [5] * 6 paper[0] = 0 result = MAX def check(x, y, nx, ny, arr): possible = True if 0 2022. 2. 7.
[JavaScript] 테트리스 웹 게임 만들기 (1) 개요 테트리스 웹 게임 만들기 (1) - 개요 간단한 개발일지를 하나 작성하고자 한다. 떠오르는 아이디어가 없어서 웹에서 동작하는 테트리스 게임을 만들어 보기로 했다. 스피드는 게임 진행 시간 기반으로 점차 빨라지도록 조절했고 스코어는 한번에 부신 블럭의 수가 많을 수록 많이 받도록 했다. 조금 심심해 보여서 좋아하는 강아지를 마스코트로 꾸며주었다. Used : html + css + javascript 처음부터 차근차근 개발일지를 작성해 보려고 하는데 단기간에 잘 작동하면 끝! 해버려서 코드가 많이 더러울 수도 있다 강의가 아니고 기록입니다 플레이하러 가기 : https://hsh5206.github.io/Tetris_Bull/ 테트리스 hsh5206.github.io RULE 한줄 제거시 +1점 두줄 제거.. 2022. 2. 7.
[백준] 12738번 - 가장 긴 증가하는 부분 수열 3 (파이썬) # 가장 긴 증가하는 부분 수열 3 import sys import bisect input = sys.stdin.readline N = int(input()) arr = list(map(int, input().split())) result = [arr[0]] for i in range(1, N): if arr[i] > result[-1]: result.append(arr[i]) else: index = bisect.bisect_left(result, arr[i]) result[index] = arr[i] print(len(result)) 이진탐색, bisect 1. 전체 리스트를 돌면서 - result의 마지막 원소보다 크면 append를 해준다 - 작으면 bisect_left를 이용하여 해당 인덱스의 .. 2022. 2. 7.
[백준] 11437번 - LCA (파이썬) # LCA import sys input = sys.stdin.readline sys.setrecursionlimit(10**5) def make_depth(node, dep): visited[node] = True depth[node] = dep for nnode in arr[node]: if not visited[nnode]: parent[nnode] = node make_depth(nnode, dep+1) def lca(x, y): if depth[x] > depth[y]: y, x = x, y while True: if depth[x] == depth[y]: break y = parent[y] for _ in range(depth[x]): if x == y: return x x = parent[x.. 2022. 2. 7.
[프로그래머스] - 자동완성 class Trie(): head = [0, dict()] def add(self, word): current = self.head current[0] += 1 for x in word: if x not in current[1]: current[1][x] = [0, dict()] current = current[1][x] current[0] += 1 def check(self, word): current = self.head result = 0 for x in word: if current[0] == 1: return result result += 1 current = current[1][x] return result def solution(words): answer = 0 T = Trie() for w.. 2022. 2. 7.
[프로그래머스] - 방금그곡 (파이썬) sound = {'A#': '1', 'C#': '2', 'D#': '3', 'F#': '4', 'G#': '5'} def solution(m, musicinfos): answer = '' result = [] m = m.replace('A#', sound['A#']) m = m.replace('C#', sound['C#']) m = m.replace('D#', sound['D#']) m = m.replace('F#', sound['F#']) m = m.replace('G#', sound['G#']) for music in musicinfos: title, time, melody = music_melody(m, music) if m in melody: result.append([title, time]) r.. 2022. 2. 6.
[프로그래머스] - 파일명 정렬 (파이썬) number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] def solution(files): arr = [['' for _ in range(3)] for _ in range(len(files))] for file in range(len(files)): do = False slice = 0 for x in range(len(files[file])): if files[file][x] in number: if not do: arr[file][0] = files[file][:x] slice = x do = True if x == len(files[file])-1: arr[file][1] = files[file][x:] if x == len(files[file].. 2022. 2. 6.