이번에 풀어본 문제는
백준 1946번 신입사원 입니다.
import java.io.*;
import java.util.*;
class Score
{
int doc,iv;
public Score(int doc, int iv)
{
this.doc = doc;
this.iv = iv;
}
}
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(br.readLine());
StringTokenizer st;
while(t-- > 0)
{
int n = Integer.parseInt(br.readLine());
List<Score> list = new ArrayList<>();
for(int i = 0; i < n; ++i)
{
st = new StringTokenizer(br.readLine());
int fst = Integer.parseInt(st.nextToken());
int sec = Integer.parseInt(st.nextToken());
list.add(new Score(fst,sec));
}
Collections.sort(list, new Comparator<Score>() {
@Override
public int compare(Score o1, Score o2) {
return o1.doc - o2.doc;
}
});
int cnt = 1;
int tmp_rank = list.get(0).iv;
int size = list.size();
for(int i = 1; i < size; ++i)
{
int cur = list.get(i).iv;
if(cur < tmp_rank)
{
cnt++;
tmp_rank = cur;
}
}
bw.write(cnt+"\n");
}
bw.flush();
bw.close();
}
}
먼저 비교 기준이 필요하기 때문에 서류등수를 기준으로 오름차순 정렬을 해줍니다. 1등을 기준으로 잡고 2등부터 순차적으로 탐색을 진행하게 되면 뒷 순서는 무조건 서류 등수가 현재보다 낮은 지원자이기 때문에 최소한 면접등수는 지금보다 높아야 합니다. 따라서 탐색을 하며 최소 등수 tmp_rank값을 계속 최신화 시켜주면서 비교해주면 조건에 맞는 지원자들을 골라낼 수 있습니다.
문제 설명이 조금 헷갈리긴 했지만, 풀이는 쉬웠던 것 같습니다.