본문 바로가기

PS10

[백준] 그래프 탐색(7562, 18352, 2606, 17198, 7569) 자동목차나이트의 이동(7562)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayDeque;import java.util.Deque;import java.util.StringTokenizer;public class Main { static int t, l, x, y, targetX, targetY, res; static int[] dx = {-1, 1, 2, 2, 1, -1, -2, -2}; static int[] dy = {2, 2, 1, -1, -2, -2, -1, 1}; static boolean[][] visited; st.. 2024. 9. 30.
[백준] 정렬(1026, 1946, 18870, 1181) 자동목차보물(1026)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] a = Arrays.stream(br.readLine().split(" ")).mapToInt.. 2024. 9. 28.
[백준] 그래프, 트리 (13116, 9934, 2210, 3187) 30번(13116)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main { public static void main(String[] args) throws IOException { /* * 1. 트리에서 자식노드 값을 2로 나누면 부모노드의 값을 구할 수 있다 * 2. a와 b를 2로 나누면서 쭉 부모노드로 올라감 * 3. 서로 공통되는 부모노드중 최댓값을 찾아야 하기때문에 a와 b중 큰값을 먼저 나눔. 값이 같아지면 반복 멈춤*/ B.. 2024. 9. 27.
[백준] 힙, 해시 테이블 (19638, 1927, 14235, 9375) 자동목차센티와 마법의 뿅망치(19638)import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class Main { 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.next.. 2024. 9. 26.
[백준] 스택, 큐 문제들 (10828, 1406, 1966, 1158) 자동목차스택(10828)import java.io.*;import java.util.*;public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); Stack stack = new Stack(); while (n-- > 0) { String[] command = b.. 2024. 9. 25.
[백준] 1920번 : 수 찾기 1920번: 수 찾기코드import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class Main { static int binarySearch(int[] arr, int a) { //이분 탐색 int pl = 0; int pr = arr.length - 1; while (pl arr[pc]) { //찾으려는 수가 중앙 인덱스값보다 클 때 pl = pc + 1; //첫인덱스값이 들어간 pl을 중앙 인덱스 + 1로 저장 } } .. 2023. 10. 26.