본문 바로가기

[java 스터디] 문제풀이 11286번 java 백준 최대 힙 문제랑 많이 비슷하다.최대 힙 문제처럼 우선순위 큐를 사용한다. 하지만 절댓값 기준으로 정렬을 해줘야 하니, Compare를 오버라이드해서 정렬의 기준을 정한다.  import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Comparator;import java.util.PriorityQueue;public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in.. 더보기
[java 스터디] 문제풀이 크리스마스 선물 14235 처음에 이 문제를 이해하는데 어려웠다. a가 0일 때마다 정렬을 하고 거기서 최대값을 뽑아야한다.이 때, 시간 복잡도는 N^2log(N)이 예상 되어 TLE가 날 것 같다. 그래서 우선순위 큐를 이용하여 정렬하는데 logN을 사용하고 NlogN이 되어 TLE가 안난다. 0이면 pq에서 poll하고0이 아니면 그 개수만큼 pq에 offer하는 것이다.  코드  package Data_Structure;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.PriorityQueue;import java.util.StringTokenizer;public class BOJ142.. 더보기
[java 스터디] 문제풀이 Result506. Relative Ranks You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique.The athletes are placed based on their scores, where the 1st place athlete has the highest score, the 2nd place athlete has the 2nd highest score, and so on. The placement of each athlete determines their rank:The 1st place athlete's rank is .. 더보기