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
- 재귀함수
- 자바PS
- dp
- GatherTown
- 다이나믹프로그래밍
- 우선순위큐
- 네트워크플로우
- COSPRO
- COSPROJAVA1급
- 세그먼트트리
- 시뮬레이션
- 게더타운시작
- 01BFS
- 백준코딩테스트
- 완전탐색
- 구현
- 알고리즘
- 엘라스틱서치
- YBMCOS
- deque
- PS
- 취득후기
- java
- 백준
- QUICKSTARTGUIDE
- 다익스트라
- 이젠 골드구현도 어렵네..
- BFS
- spring
- DFS
Archives
- Today
- Total
공부공간
BOJ - 3020 ) 개똥벌레 본문
https://www.acmicpc.net/problem/3020
석순의 높이를 정렬하여 만나는 개수를 COUNT해준다.
종유석의경우 동일하게 구한다음, 최종 높이에서 개수를 구할 때에 H-index번째의 개수를 참조한다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class BOJ3020 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int H = Integer.parseInt(st.nextToken());
int h1[] = new int[N>>1];
int h2[] = new int[N>>1];
for(int i=0;i<N;i++) {
int h = Integer.parseInt(br.readLine());
if(i%2==0) {
h1[i/2] = h;
} else {
h2[i/2] = h;
}
}
Arrays.sort(h1);
Arrays.sort(h2);
int H1[] = new int[H+1];
int H2[] = new int[H+1];
int cnt =0;
int pos =(N>>1)-1;
int j;
for(j=H;j>=0 && pos >=0 ;j--) {
while(pos>=0&&j==h1[pos]) {
cnt++;pos--;
}
H1[j]=cnt;
}
while(j>=1) {
H1[j--] = cnt;
}
cnt=0;pos=(N>>1)-1;
for(j=H;j>=0&&pos>=0 ;j--) {
while(pos>=0&&j==h2[pos]) {
cnt++;pos--;
}
H2[j]=cnt;
}
while(j>=1) {
H2[j--] = cnt;
}
int answer =987654321;
int answercnt=0;
for(int i=1;i<=H;i++) {
int now = H1[i]+H2[H-i+1];
if(answer > now) {
answer = now;
answercnt=1;
} else if(answer == now){
answercnt++;
}
}
System.out.println(answer+" "+answercnt);
}
}
'알고리즘 > 구현,시뮬' 카테고리의 다른 글
BOJ - 7662 ) 이중 우선순위 큐 (0) | 2022.03.01 |
---|---|
BOJ - 1475 ) 방번호 (0) | 2022.02.27 |
BOJ - 5373 ) 큐빙 (0) | 2021.10.02 |
[JAVA] Programmers 위클리 챌린지 1~8주 풀이 (1) | 2021.09.30 |
BOJ - 1120 ) 문자열 (0) | 2021.09.13 |
Comments