[BOJ 19637] IF๋ฌธ ์ข ๋์ ์จ์ค
1. ๋ฌธ์ : https://www.acmicpc.net/problem/19637
2. ํ์ด
๋น๊ตํ๋ ์กฐ๊ฑด์ ์ด์งํ์์ผ๋ก ๊ณจ๋ผ์ ๋น๊ต
3. ์ฝ๋
package baekjoon;
import java.util.*;
import java.io.*;
public class IF๋ฌธ์ข๋์ ์จ์ค {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(br.readLine());
StringBuilder sb=new StringBuilder();
int N=Integer.parseInt(st.nextToken());
int M=Integer.parseInt(st.nextToken());
String[][] title=new String[N][2];
for(int i=0;i<N;i++){
st=new StringTokenizer(br.readLine());
title[i][0]=st.nextToken();
title[i][1]=st.nextToken();
}
for(int i=0;i<M;i++){
int num=Integer.parseInt(br.readLine());
int left=0;
int right=N-1;
int mid=(left+right)/2;
while(left<=right){
mid=(left+right)/2;
int titleInt=Integer.parseInt(title[mid][1]);
if(titleInt<num){
left=mid+1;
}
else{
right=mid-1;
}
}
sb.append(title[left][0]+"\n");
}
System.out.print(sb);
}
}
'๐ป Coding Problems Solving > Two Pointers | Binary Search| LinkedList' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ 2110] ๊ณต์ ๊ธฐ ์ค์น (0) | 2023.09.06 |
---|---|
[BOJ 2343] ๊ธฐํ ๋ ์จ (0) | 2023.09.05 |
[BOJ 2512] ์์ฐ (0) | 2023.08.27 |
[LeetCode] Add Two Numbers (0) | 2023.07.13 |
[LeetCode] Remove Duplicates from Sorted List II (0) | 2023.07.12 |
์ต๊ทผ๋๊ธ