분류 전체보기

    LCS2 [백준 9252] - python

    LCS2 [백준 9252] - python

    def BOJ9252(): first = input() second = input() array = [[[0, '']] * (len(second) + 1) for _ in range(len(first) + 1)] l = [] for i in range(1, len(first) + 1): for j in range(1, len(second) + 1): if first[i-1] == second[j-1]: array[i][j] = [array[i-1][j-1][0] + 1, array[i-1][j-1][1] + first[i-1]] else: if array[i-1][j][0] > array[i][j-1][0] : array[i][j] = [array[i-1][j][0], array[i-1][j][1]] e..

    세상을 향해 지랄할수 있는 그냥 하기의 힘(역시 인생은 열심히 하는 맛에 사는 거지!)

    세상을 향해 지랄할수 있는 그냥 하기의 힘(역시 인생은 열심히 하는 맛에 사는 거지!)

    제목이 내기준 자극적이었다.(그래서 눈에 띄었다) mbti 마지막 글자?(마지막 글자로 표현하는게 맞을까?)가 j인 나에게 그냥 하기란 없다. 철저한 계획은 최선이자 최소라고 생각하니까 그래서 궁금했다. 책을 읽기 전에 느낌은 일의 계획을 짜서 행하는 것에 대한 주제이기 보다는 망설이고 걱정이 앞서 행하지 못하는 것에 대한 내용이 아닐까 싶었다. 아래는 책을 읽고 나서 맘에드는 문구들이다. * 셋째, 완벽함과 결별하기로 한다 - 무언가를 도전하는 데 완벽한 시기를 기다린다면 당장 그만두는 것이 좋다. 야심이 넘치는 것은 좋지만 완벽한 타이밍을 기다리는 일은 비효율적이고 비현실 적이다. "완벽한 순간을 기다리는 것보다 실행에 옮기는 것이 훨씬 더 현명한 선택이다." => 예전부터 완벽한 시기를 기다리다가 ..

    사다리 [백준 2022] - python

    사다리 [백준 2022] - python

    def get_c(x, y, width) : h1 = (x**2 - width**2)**0.5 h2 = (y**2 - width**2)**0.5 c = h1 * h2 / (h1 + h2) return c def BOJ2022() : x, y, c = map(float, input().split()) start, end = 0, min(x,y) res = 0 while (end - start) > 0.000001 : width = (start + end) / 2 res = width if get_c(x, y, width) >= c : # c를 구했는데 기존의 c보다 같거나 크면 w값을 키워주어서 h1, h2의 값을 작게 해주어야 한다. start = width else : end = width print(..

    후위 표기식 2[백준 1935] - python

    후위 표기식 2[백준 1935] - python

    import string def BOJ1935() : n = int(input()) quest = input() numbers = {} for i in string.ascii_uppercase[:n] : numbers[i] = float(input()) stack = [] ord = {'+': 1, '-': 1, '*': 2, '/': 2} for s in list(quest) : if s in ord : second = stack.pop() first = stack.pop() temp = 0 if s == '+' : temp = first + second elif s == '-' : temp = first - second elif s == '*': temp = first * second elif s =..

    다각형의 면적 [백준 2166] - python

    다각형의 면적 [백준 2166] - python

    import sys import math input = sys.stdin.readline def BOJ2166() : N = int(input()) x_points = [] y_points = [] for _ in range(N) : x, y = map(int, input().split()) x_points.append(x) y_points.append(y) result = 0 for i in range(N) : if i == N-1 : result += x_points[i] * y_points[0] else : result += x_points[i] * y_points[i+1] for i in range(N): if i == N-1 : result -= x_points[0] * y_points[i] e..

    가장 긴 증가하는 부분 수열 4 [백준 14002] - python

    가장 긴 증가하는 부분 수열 4 [백준 14002] - python

    import sys from bisect import bisect_left input = sys.stdin.readline def BOJ14002(): N = int(input()) A = list(map(int, input().split())) dist = [-1000000001] index = [0] * (N + 1) for i in range(len(A)): num = A[i] if dist[-1] < num: dist.append(num) index[i] = len(dist) - 1 else: index[i] = bisect_left(dist, num) dist[index[i]] = num max_length = len(dist) - 1 print(max_length) answer = [] for..

    N번째 큰 수[백준 2075번] - python

    N번째 큰 수[백준 2075번] - python

    정답코드 먼저 살펴보자 import sys, heapq def BOJ2075(): n = int(input()) array = list(map(int, sys.stdin.readline().split())) for _ in range(n-1) : for i in list(map(int, sys.stdin.readline().split())): if array[0] < i : heapq.heappop(array) heapq.heappush(array, i) print(array[0]) BOJ2075() 맨 처음에는 배열로 입력받지 않고 배열에 값을 하나씩 넣은다음에 전체를 정렬후 값을 출력했었다. 문제의 조건은 12mb이다. 메모리 초과로 바로 실패했다. 쉽사리 방법을 떠올리지 못했고 다른 분들의 블로그를..

    가장 긴 증가하는 부분 수열 3

    가장 긴 증가하는 부분 수열 3

    import sys from bisect import bisect_left input = sys.stdin.readline def BOJ12738(): N = int(input()) A = list(map(int, input().split())) dist = [-1000000001] index = [0] * (N + 1) for i in range(len(A)): num = A[i] if dist[-1] < num: dist.append(num) else: index[i] = bisect_left(dist, num) dist[index[i]] = num max_length = len(dist) - 1 print(max_length) BOJ12738() 접근 방법 0. 거리 배열을 하나 두자 1. 거리 배..

    치킨 배달[백준 15686] - python

    치킨 배달[백준 15686] - python

    정답 코드 import sys from itertools import combinations def BOJ15686() : N, M = map(int, sys.stdin.readline().split()) graph = [] for _ in range(N) : graph.append(list(map(int, sys.stdin.readline().split()))) chiken_store_list = [] house_list = [] for x in range(N) : for y in range(N) : if graph[x][y] == 1 : house_list.append([x+1, y+1]) elif graph[x][y] == 2 : chiken_store_list.append([x+1, y+1]) c..

    평범한 배낭[백준 12865] - python

    평범한 배낭[백준 12865] - python

    dp를 접하게 되면 꼭 나오는 냅색(knapsack) 문제이다. 예전에 제대로 학습해두지 않았었고 결국 다른 분들의 코드를 참고했다 import sys def BOJ12865() : n, k = map(int, sys.stdin.readline().split()) item_list = [[0,0]] dp = [[0] * (k+1) for _ in range(n+1)] for _ in range(n) : w,v = map(int, sys.stdin.readline().split()) item_list.append([w,v]) for i in range(1, n+1) : for j in range(1, k+1) : weight, value = item_list[i] if item_list[i][0]