Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- framework
- ES
- 자바
- 코딩
- Java
- 코딩테스트
- Baekjoon
- JPA
- 그리디
- database
- 애자일기법
- API
- cleancode
- 데이터베이스
- Spring
- 개발자
- 프레임워크
- spring boot
- 애자일프로그래밍
- 클린코드
- 엘라스틱서치
- 애자일
- 백준
- 개발
- 코드
- 읽기쉬운코드
- 스프링
- Elasticsearch
- 그리디알고리즘
- 알고리즘
Archives
- Today
- Total
튼튼발자 개발 성장기🏋️
[1946번] 신입 사원 본문
반응형
문제 기출 : [https://www.acmicpc.net/problem/1946]
풀이 방법
[그리디알고리즘] 접근
문제를 읽고 "이건 무조건 객체 정렬이다!"라고 생각했다. 가장 먼저 서류 설적과 면접 성적을 따로 받고 두 성적에 대해 제한을 두고 있으니 당연한 것이 아닌가.
객체 정렬 후 오직 면접 성적만을 비교하여 큰 값을 갱신해가며 카운팅하면 된다.
|
문제 풀이
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int answer = 0;
try {
int testCase = Integer.parseInt(br.readLine());
int[][] scores = {};
for (int i = 0; i < testCase; i++) {
answer = 0;
int people = Integer.parseInt(br.readLine());
scores = new int[people][2];
for (int j = 0; j < people; j++) {
StringTokenizer score = new StringTokenizer(br.readLine(), " ");
scores[j][0] = Integer.parseInt(score.nextToken());
scores[j][1] = Integer.parseInt(score.nextToken());
}
Arrays.sort(scores, new Comparator<int[]>() {
@Override
public int compare(int[] arg0, int[] arg1) {
if (arg0[1] == arg1[1]) {
return arg0[1] - arg1[1];
} else {
return arg0[0] - arg1[0];
}
}
});
int temp = scores[0][1];
for (int j = 1; j < scores.length; j++) {
if(temp > scores[j][1]) {
answer++;
temp = scores[j][1];
}
}
System.out.println(answer+1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
반응형
'Business logic > 백준' 카테고리의 다른 글
[2352번] 반도체 설계 (0) | 2020.04.15 |
---|---|
[2217번] 로프 (0) | 2020.04.15 |
[1969번] DNA (0) | 2020.04.13 |
[1931번] 회의실배정 (0) | 2020.04.13 |
[1541번] 잃어버린 괄호 (0) | 2020.04.12 |