본문 바로가기

전체 글

[Python][백준 2839번] 설탕배달 # https://www.acmicpc.net/problem/2839 # 1. '설탕kg'을 입력받는다. # 2. 봉지개수 변수 count 선언 # 3. while문을 계속 돈다 # 1) 입력받은 '설탕kg'이 5로 정확히 나누어떨어진다면, 그 몫을 count에 더해 출력한다 # 2) 나누어떨어지지 않으면 '설탕kg' -= 3 을 해주고 # 3) count += 1 증가. 왜 ? 3kg 봉지를 하나 사용한 것이므로 # 4) 만약 계속 빼다가 '설탕kg'이 < 0 하다면, 3, 5 kg 의 봉지 조합으로 담을 수 없는 무게이므로 -1 출력 Honey = int(input()) cnt = 0 while True : if ( Honey % 5 == 0 ) : cnt = cnt + ( Honey // 5 ) p.. 더보기
Effectivce C++ #define 대신 const, enum, inline http://www.yes24.com/Product/Goods/17525589 Effective C++ 이펙티브 C++ - YES24 www.yes24.com // 1. #define을 쓰려거든 const, enum, inline #define ASPECT_RATIO 1.653 // 1. const ----------------------------------------------------------------------------------------------------------------------------- /* 컴파일러 입장에서는 ASPECT_RATIO가 기호식 이름으로 전혀 보이지 않는다. 컴파일러에게 넘어가기 전에 선행 처리자(전처리기)가 밀어버리고 숫자 상수로 바꿔어 버리기 때문이다... 더보기
[Python][백준 16389번] 행성연결 # https://www.acmicpc.net/submit/16398/35563479 # 크루스칼 --- N = int(input()) csts = [list(map(int,input().split())) for _ in range(N)] def find_parent(parent,x): if parent[x] != x : parent[x] = find_parent(parent,parent[x]) return parent[x] def union_parent(parent,a,b) : a = find_parent(parent,a) b = find_parent(parent,b) if a > b : parent[a] = b else : parent[b] = a # 부모 세팅 parent = [-1] * N for.. 더보기
[Python][백준 1261 번] 알고스팟 # https://www.acmicpc.net/problem/1261 import sys import heapq from collections import Counter , deque sys.setrecursionlimit(100000) dx = [-1,1,0,0] dy = [0,0,-1,1] M,N = map(int,input().split()) mirrors = [list(map(int,input())) for _ in range(N)] dist = [[-1] * M for _ in range(N)] q = deque() dist[0][0] = 0 q.append((0,0,0)) ans = int(1e9) while q : x,y,d = q.popleft() if x == N-1 and y == M .. 더보기
[Python][백준 12869 번] 뮤탈리스크 # https://www.acmicpc.net/problem/12869 ''' 3차원 dynamic 문제 풀이 d[i][j][k] : scv의 체력이 i,j,k 일때 모두 파괴하는 최소 공격횟수 -- 공격할 수 있는 횟수 : 3팩토리얼 = 6가지 ex) d[i][j][k] = d[i-9][j-3][k-1] + 1 [i-9][j-3][k-1] 같은 경우 음수가 되면 모두 0으로 처리해주면서 진행 -- 사실 dp 를 구현할 수 있는 방법은 총 2가지 이다. 1) top - down 2) bottom - up bottom - up 같은 경우 idx 에 직접 접근하는 형식을 띤다 하지만, 여기서는 idx가 중간에 음수가 되는 경우가 매우 많다 예외처리를 해주어야 한다는 것이다 ex) 하나의 idx : i 에 대.. 더보기
[Python][백준 15565 번] 강의실 배정 # https://www.acmicpc.net/problem/15565 # 슬라이딩 윈도우 ''' 라이언 인형이 딱 K개가 되는 구간만 확인해주면 된다 "항상 K개가 되는 것을 확인해야 하므로, 슬라이딩 윈도우를 활용할 수 있는 것이다" 라이언들의 idx들을 구해놓는다 0 4 6 9 K가 3이라면 0 4 6 4 6 9 라는 2개의 set가 존재하게 되며 처음 idx - 마지막 idx + 1 을 해주면 인형이 포함된 전체 인형의 개수가 된다 윈도우의 크기를 K로 유지하면 한칸씩 뒤로 밀어가며 계속 비교해가면 된 ''' N ,K = map(int,input().split()) dolls = list(map(int, sys.stdin.readline().split())) lion = [] # 라이언 위치 저장.. 더보기
[Python][백준 11000번] 강의실 배정 # https://www.acmicpc.net/problem/11000 import itertools from copy import deepcopy import heapq import sys from collections import deque, defaultdict, Counter sys.stdin = open("input.txt", "rt") sys.setrecursionlimit(100000) N = int(input()) classes = [] for _ in range(N): st, ed = map(int, input().split()) classes.append((st, ed)) # 시작 시간 기준 정렬 classes = sorted(classes, key=lambda x: x[0]) # 강의.. 더보기
[Python][백준 21608번] 상어초등학교 # https://www.acmicpc.net/problem/21608 from copy import deepcopy import sys from collections import deque, defaultdict, Counter sys.stdin = open("input.txt", "rt") sys.setrecursionlimit(100000) dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] N = int(input()) sits = [[0]*N for _ in range(N)] def chMostLoves(sits, loves): res = [] maxN = 0 for r in range(N): for c in range(N): if sits[r][c] != 0: continue .. 더보기