분류 전체보기 67

[C++] 프로그래머스 - 이중우선순위큐

풀이 문제에서 요구하는 것은 최댓값과 최솟값 뿐이다. 그러므로, 오름차순 priority_queue, 내림차순 priority_queue, 이렇게 두개로 관리한다. 삽입은 양쪽에 해주되, 최대값 삭제는 내림차순에서, 최소값 삭제는 오름차순에서 진행한다. #include #include #include #include using namespace std; vector solution(vector operations) { vector answer; priority_queue pqD; priority_queue pqU; int cnt = 0; for(int i=0; i> oper >> num; if(oper == "I") { pqD.push(stoi(num)); pqU.push(stoi(num)); cnt++..

코딩테스트 2024.04.15

[C++] 프로그래머스 - 프로세스

스케줄러 같은 문제다. 신경써야 할 부분은 두가지가 있었다. 1. location에 해당하는 프로세스를 기억하고 있을 것 2. 프로세스가 빠진다면, 그 프로세스의 우선순위도 빠져야 한다는 것 두번째 것을 처음에 생각하지 못해 약간 삽질을 했다. #include #include #include using namespace std; int solution(vector priorities, int location) { queue q; priority_queue pq; for(int i=0; i= pq.top()) { if(temp.first == location) { return cnt; } pq.pop(); cnt++; } else { q.push(temp); } } } 풀이 1. priority_queue..

코딩테스트 2024.04.14

[C++][완전탐색] 프로그래머스 - 피로도

# 풀이 우선 던전의 최대 개수가 8개밖에 되지 않는다! 그냥 무식하게 for문을 돌려도 시간 초과가 나지는 않을 것 같았다. 우선 처음 생각해본 방법으로는, 1. next_permutation을 써서 던전 도는 순서의 순열을 생성하고 2. 그 순서대로 던전을 돌면서 최대값을 계속 갱신해 주는 것이다. #include #include #include using namespace std; int solution(int k, vector dungeons) { int answer = -1; vector idx; vector idxTmp(8); for(int i=0; i

코딩테스트 2024.03.11

[C++][정렬] 프로그래머스 - 가장 큰 수

1. 문제 우선 수들을 조합해서 가장 큰 수를 만드는 문제이다. 최초에는 당연히 next_permutation을 사용해서 풀어보았다 #include #include #include using namespace std; string solution(vector numbers) { string answer = ""; vector tmp; sort(numbers.begin(), numbers.end()); do { string s = ""; for(auto it = numbers.begin(); it != numbers.end(); ++it) { s += to_string(*it); } tmp.push_back(stoi(s)); } while(next_permutation(numbers.begin(), num..

코딩테스트 2024.03.05

[C++][해시] 프로그래머스 - 완주하지 못한 선수

참가자 중에는 동명이인이 있을수 있다에 주목했다. 중복된 원소가 필요하다는 뜻이므로 unordered_multiset을 사용했다. 완주자의 수가 항상 참가자의 수보다 1 작으므로, 단순하게 생각하여 모든 참가자의 해시테이블에서 완주자를 한명씩 제거해 나가면 완주하지 못 한 1명이 남을 것이다. #include #include #include using namespace std; string solution(vector participant, vector completion) { string answer = ""; unordered_multiset us(participant.begin(), participant.end()); for(int i=0; i

코딩테스트 2024.03.04

[C++][해시] 프로그래머스 - 폰켓몬

기본적인 해시 문제이다. unordered_set은 중복을 허용하지 않으므로 벡터에 들어있는 모든 숫자들을 unordered_set에 삽입하면 자연스럽게 폰켓몬의 종류를 구할 수 있다. 예외사항으로, 폰켓몬의 종류가 N/2보다 클 수 있으니, 해당 경우에만 예외처리를 해주면 무리없이 통과할 수 있는 문제였다. #include #include using namespace std; int solution(vector nums) { int answer = 0; int cnt = 0; unordered_set us; for(int i=0; i

코딩테스트 2024.03.04

[Unity 2D] OverlapCapsuleAll 판정 범위

1. Physics2D.OverlapCapsuleAll(transform.position, capsuleCollider.size, CapsuleDirection2D.Horizontal, 0f); 2. 이 코드가 콜라이더의 크기를 그대로 가져와서 판정을 하는 코드인 줄 알았음. 3. 그러나 실제로는 - 파란 동그라미 친 부분처럼 이상한 부분만을 판정하고 있었음 ### 원인 - 콜라이더가 Horizontal로 설정되어 있었음 - 로컬 스케일을 적용하지 않았음 ### 해결 Collider2D[] aegsoniaColliders = Physics2D.OverlapCapsuleAll(transform.position, new Vector2(capsuleCollider.size.y * capsuleCollider...

[DB] WITH, CASE, RECURSIVE, JOIN vs NESTED

#with 절- liveoralce에서는with bigdepts(bdno)    (select dno    from employee    group by dno    having count(*) > 3)select dno, count(*)from employeewhere salary > 40000 and dno in (select bdno from bigdepts) #case 문- live oracle에서는 마지막에 END; 로 끝나야 함 #Recursive- live oracle에서는 지원 안함 #JOIN vs NESTED- 사람이 이해하기는 nested가 쉽지만 연산 효율은 join이 더 좋음- nested는 for 루프처럼 돌아감.ex) r은 100개 튜플, s는 1000개 튜플이라면> nested..

CS/DB 2023.09.26

[정보보호] 모듈러 연산, 갈로아 필드

※복습- 대칭키 : 치환, 전치 두가지만 있으면 됨    > 치환: 교체(ex. S-Box)    > 전치: 순서 교체  #유클리드 호제법    > 최대공약수 찾기 -> gcd(a, b) #모듈러 연산1. 법- a % n 수행시 n = 법- a % n == b % n 이라면, a≡b(mod n) -> a, b는 법 n에 대해 합동- a ≡ 0 (mod n) 이면, n | a임 - 유클리드 호제법에 대한 재고> 재귀함수로 구현 가능 - 확장 유클리드 호제법    > 최대공약수 d 뿐만 아니라 ax+by=d=gcd(a, b)를 만족하는 x와 y를 구할 수 있음    > x, y의 부호가 다른 것은 자명    > a=42, b=30일때 x, y는? (gcd(42, 30)=6 임에 주목) #군(groups), ..

CS/정보보호 2023.09.20