본문 바로가기

Problem Solving83

[Python] 디스크 컨트롤러 https://programmers.co.kr/learn/courses/30/lessons/42627 코딩테스트 연습 - 디스크 컨트롤러 하드디스크는 한 번에 하나의 작업만 수행할 수 있습니다. 디스크 컨트롤러를 구현하는 방법은 여러 가지가 있습니다. 가장 일반적인 방법은 요청이 들어온 순서대로 처리하는 것입니다. 예를 programmers.co.kr Point 힙 자료구조를 이용해 SJF로 비선점 스케쥴링을 구현해볼 수 있는 문제 Tip 시작 전 jobs을 정렬해준다 현재 시간에 해당하는 job을 jobs에서 모두 꺼내주고 Min Heap에 저장한다. 이때 처리시간이 가장 짧은 순으로(SJF) 정렬된다. 컨트롤러에 처리중인 job이 있을 때, 반환시간과 현재시간이 같다면 컨트롤러에서 내리고 총 소요시간.. 2021. 9. 26.
[Python] 전화번호 목록 https://programmers.co.kr/learn/courses/30/lessons/42577 코딩테스트 연습 - 전화번호 목록 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 구조 programmers.co.kr Point 해쉬를 이용한 문제로, 트라이(Trie) 자료구조를 응용해서 풀어보기 좋은 문제이다. 실제로 많은 분들이 리스트와 반복문을 이용해서 풀고 있는데, 만약 문제의 제약조건이 타이트했다면 해결하기 어려울 것이다. Tip 정렬을 하지 않는 것이, 최악 테스트케이스에서 수행 시간이 더 빠르다. 따라서 prefix+a 문자열이 이미 트라이에 있을 때, pre.. 2021. 9. 25.
[Python] LongestPassword https://app.codility.com/demo/results/trainingPB6C9Y-2CD/ Test results - Codility You would like to set a password for a bank account. However, there are three restrictions on the format of the password: it has to contain only alphanumerical characters (a−z, A−Z, 0−9); there should be an even number of letters; there should be an app.codility.com Point 제시된 조건에 따라 validation check를 수행한다 스플릿 하여 fo.. 2021. 7. 18.
[Python] TreeHeight https://app.codility.com/demo/results/trainingMGZBGQ-R79/ Test results - Codility In this problem we consider binary trees, represented by pointer data structures. A binary tree is either an empty tree or a node (called the root) consisting of a single integer value and two further binary trees, called the left subtree and the right sub app.codility.com Point dfs를 이용해서 height(depth)를 카운트한다 Tip 탈.. 2021. 7. 18.
[Python] StrSymmetryPoint https://app.codility.com/demo/results/trainingYMXCBY-VNE/ Test results - Codility Write a function: def solution(S) that, given a string S, returns the index (counting from 0) of a character such that the part of the string to the left of that character is a reversal of the part of the string to its right. The function should return − app.codility.com Point center point까지 start와 end를 반복문을 통해 비교해.. 2021. 7. 18.
[Python] FirstUnique https://app.codility.com/demo/results/training5MBAYJ-A83/ Test results - Codility A non-empty array A consisting of N integers is given. The unique number is the number that occurs exactly once in array A. For example, the following array A: A[0] = 4 A[1] = 10 A[2] = 5 A[3] = 4 A[4] = 2 A[5] = 10 contains two unique numbers (5 and 2). Y app.codility.com Point 딕셔너리를 만들어 입력값에 대해 카운트를 한다 딕셔너리 for l.. 2021. 7. 15.
[Python] DisappearingPairs https://app.codility.com/demo/results/trainingFRJG6A-A4D/ Test results - Codility A string S containing only the letters "A", "B" and "C" is given. The string can be transformed by removing one occurrence of "AA", "BB" or "CC". Transformation of the string is the process of removing letters from it, based on the rules described above. A app.codility.com Point 전형적인 stack과 관련된 알고리즘 입력값과 stack의 가장 .. 2021. 7. 15.
[Python] 20056. 마법사 상어와 파이어볼 www.acmicpc.net/problem/20056 20056번: 마법사 상어와 파이어볼 첫째 줄에 N, M, K가 주어진다. 둘째 줄부터 M개의 줄에 파이어볼의 정보가 한 줄에 하나씩 주어진다. 파이어볼의 정보는 다섯 정수 ri, ci, mi, si, di로 이루어져 있다. 서로 다른 두 파이어볼의 위치 www.acmicpc.net Point 첫 입력에서 서로 다른 두 파이어볼 위치가 같은 경우는 없음 파이어볼 질량이 0 이 되면 소멸 Tip 2차원 리스트 배열을 선언하여 이동이 끝난 뒤 파이어볼 합치기/분열을 연산 파이어볼의 방향을 연산할 때, 총합이 짝수/홀수냐로 모두 짝수/홀수인지 아닌지를 판별하면 안된다. 짝짝홀홀일 때 총합은 짝수이기 때문이다. 메모리 (제한: 512MB) 138280 KB .. 2021. 4. 24.
[Python] 20057. 마법사 상어와 토네이도 www.acmicpc.net/problem/20057 20057번: 마법사 상어와 토네이도 마법사 상어가 토네이도를 배웠고, 오늘은 토네이도를 크기가 N×N인 격자로 나누어진 모래밭에서 연습하려고 한다. 위치 (r, c)는 격자의 r행 c열을 의미하고, A[r][c]는 (r, c)에 있는 모래의 양을 www.acmicpc.net Point 토네이도가 (0,0) 도달 시 종료 한칸 움직일 때마다 모래를 퍼트림 Tip 반시계 방향 회전가능할 때까지 전진 시간 절약을 위해 현 위치의 모래가 0이 아닐때만 (A[y][x] != 0) 모래를 퍼트림 메모리 (제한: 512MB) 132984 KB 시간 (제한: 1초) 476 ms 결과 100% import sys from collections import deque.. 2021. 4. 24.
728x90
반응형