전체 글
-
[백준] Python - 최대힙메모/알고리즘 2021. 9. 19. 13:43
11279번: 최대 힙 첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 www.acmicpc.net 최대 힙에서 최댓값을 뽑아오는 문제다. 우선순위 큐를 이용한다. 처음에는 재귀함수로 구현했는데 시간초과가 나서 어떻게 할까 고민하면서 알고리즘 자료 + 다른 사람 코드 해서 조금 바꿔봤다. 아래는 파이썬 코드 더보기 import sys n = int(sys.stdin.readline()) hArr = [0 for i in range(0, n)] size = 0 def push(num): global size global hArr size += ..
-
[백준] Go, Python - 후위 표기식 2메모/알고리즘 2021. 9. 17. 22:20
https://www.acmicpc.net/problem/1935 1935번: 후위 표기식2 첫째 줄에 피연산자의 개수(1 ≤ N ≤ 26) 가 주어진다. 그리고 둘째 줄에는 후위 표기식이 주어진다. (여기서 피연산자는 A~Z의 영대문자이며, A부터 순서대로 N개의 영대문자만이 사용되며, 길이 www.acmicpc.net 후위 표기식 문제다. 문제 자체는 정말 쉽다. 그런데 Go로 한번 해보겠다고 Go로 코드 짰는데 계속 틀렸다고 나온다. 귀신같이 파이썬으로 알고리즘만 유지해서 작성하니까 맞았다... 열받네... Go, Python 코드는 아래서 확인 더보기 참고로 Go 코드는 틀린 코드라고 나온다! 누군가 무슨 문제인지 안다면 알려주.... https://github.com/Floodnut/Algori..
-
[OpenCV] 환경 구성개발/Python 2021. 9. 14. 14:51
OpenCV 실습을 위해 환경을 구성을 먼저 진행하려 한다. 파이참에 파이썬 3.9를 이용할 것이다. 파이썬 가상 환경을 venv를 쓸지 아나콘다를 쓸지 고민했는데 아나콘다를 써보려다가 opencv 버전 문제로 그냥 원래 쓰던 venv 쓰도록 하겠다. 또, 사실 VS Code로 리눅스 ssh 붙여 쓰는 게 익숙한데 실습 환경이 파이참이라 그냥 파이참 쓰기로 했다. 이미지는 아나콘다인데 실제로는 venv다. 실습하는 PC는 기본적으로 파이썬 3.8이 설치되어있었다. 나는 따로 3.9를 설치해주었는데 파이참 설정 페이지에서 현재 프로젝트의 파이썬 관련 패키지들의 버전을 확인할 수 있다. 이제 내 파이썬 가상 환경에 필요한 패키지를 설치해줄 것이다. 나는 우선 opencv-python을 검색해서 4.5 버전을..
-
[백준] Python - 그룹 단어 체커메모/알고리즘 2021. 9. 9. 20:51
1316번: 그룹 단어 체커 그룹 단어란 단어에 존재하는 모든 문자에 대해서, 각 문자가 연속해서 나타나는 경우만을 말한다. 예를 들면, ccazzzzbb는 c, a, z, b가 모두 연속해서 나타나고, kin도 k, i, n이 연속해서 나타나기 때 www.acmicpc.net 그룹 단어 체커 문제이다. 1개 이상의 같은 알파벳끼리는 모여있어야한다. ex) abcdddd -> a, b, c, d가 각각 모여있으니 그룹 단어. abababc -> a, b가 자기 끼리 모여있지 않으니 그룹 단어가 아님. 파이썬을 활용했고 다른 더 좋은 알고리즘이 충분히 존재할 수 있다. 나는 인덱스 0부터 문자열의 끝 인덱스까지 탐색하며 현재 위치의 알파벳의 인덱스를 딕셔너리에 저장했다. 그리고 다른 인덱스를 검증할 때 기..
-
[백준] Python - 염색체메모/알고리즘 2021. 9. 9. 20:44
9342번: 염색체 상근이는 생명과학 연구소에서 염색체가 특정한 패턴인지를 확인하는 일을 하고 있다. 염색체는 알파벳 대문자 (A, B, C, ..., Z)로만 이루어진 문자열이다. 상근이는 각 염색체가 다음과 같은 규칙 www.acmicpc.net 문자열 처리 문제 '염색체' 이다. 영문자 대문자로 이루어진 문자열 중 특정 문자를 포함한다면 Infected!, 아니라면 Good을 출력한다. 잠깐 고민하고 바로 정규표현식을 활용하기로 했다. 언어는 파이썬 3.8 을 사용했고 해결한 코드는 아래와 같다. 더보기 #https://github.com/CASPER-REPSAC/algorithm-stack/blob/gsniper777/baekjoon/9342 import re, sys regex = re.comp..