문제풀기(63)
-
프로그래머스 위장
https://programmers.co.kr/learn/courses/30/lessons/42578 코딩테스트 연습 - 위장 programmers.co.kr 고등학생 때 배우는 '확률과 통계'를 구현하는 느낌이다. 각 옷의 type별로 가지고 있는 옷 개수를 세고, 옷 개수 +1의 곱들에서 아무것도 안입은 경우 한 번을 빼주면 된다. def solution(clothes): answer = 1 cloth_dict = dict() for cloth,types in clothes: if types in cloth_dict: cloth_dict[types] += 1 else: cloth_dict[types] = 2 for t in cloth_dict: answer *= cloth_dict[t] answer ..
2021.10.12 -
프로그래머스 : 괄호 회전하기
https://programmers.co.kr/learn/courses/30/lessons/76502 코딩테스트 연습 - 괄호 회전하기 programmers.co.kr 자료구조 중 Stack을 이용하는 문제이다. from collections import deque def solution(s): answer = 0 right = ["(","[","{"] left = [")","]","}"] for i in range(len(s)): stack = deque([]) strs = deque(list(s[:])) result = True while strs: now = strs.popleft() if now in left: now_index = left.index(now) if len(stack) > 0: c..
2021.10.08 -
프로그래머스 : 후보키
https://programmers.co.kr/learn/courses/30/lessons/42890 코딩테스트 연습 - 후보키 [["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]] 2 programmers.co.kr itertools의 combinations를 이용해서 완전 탐색을 하면 된다. from itertools import combinations def solution(relation): answer = 0 already = [] columns..
2021.10.08 -
프로그래머스 : 예상 대진표
https://programmers.co.kr/learn/courses/30/lessons/12985 코딩테스트 연습 - 예상 대진표 △△ 게임대회가 개최되었습니다. 이 대회는 N명이 참가하고, 토너먼트 형식으로 진행됩니다. N명의 참가자는 각각 1부터 N번을 차례대로 배정받습니다. 그리고, 1번↔2번, 3번↔4번, ... , N-1번↔N programmers.co.kr import math def solution(n,a,b): answer = 1 divide = 2 while True: if math.ceil(a/divide) == math.ceil(b/divide): return answer else: answer +=1 divide *= 2 return answer
2021.10.08 -
백준 22860번 : 폴더 정리(small)
https://www.acmicpc.net/problem/22860 22860번: 폴더 정리 (small) main 폴더 하위에는 FolderA 폴더 하위에 있는 File1, File2, FolderB 폴더 하위에 있는 File1, File3이 있다. 파일의 종류는 File1, File2, File3 총 3가지이고, 파일의 총 개수는 File1, File2, File1, File3 총 4개이다. mai www.acmicpc.net 아이디어 최근 본 코딩테스트에서 거의 똑같은 문제가 나왔었다. 근데 또 문제 잘못 읽음...ㅎㅎ 출력 순서를 반대로 했었다. 위상정렬 아이디어를 사용했다. folder_dict에서 각 key에 해당하는 value는 길이가 3인 리스트로 구성되어있다. 0번 인덱스는 해당 폴더의 ..
2021.10.06 -
백준 14567번 : 선수과목 (Prerequisite)
https://www.acmicpc.net/problem/14567 14567번: 선수과목 (Prerequisite) 3개의 과목이 있고, 2번 과목을 이수하기 위해서는 1번 과목을 이수해야 하고, 3번 과목을 이수하기 위해서는 2번 과목을 이수해야 한다. www.acmicpc.net 아이디어 전형적인 위상정렬 문제이다. import sys from collections import deque input = sys.stdin.readline n,m = map(int,input().rstrip().split()) routes = [0] * (n+1) graph = [[] for _ in range(n+1)] for _ in range(m): a,b = map(int,input().rstrip().split..
2021.10.05