코딩테스트/[백준] 코딩테스트 연습

    욕심쟁이 판다 - 1937번

    욕심쟁이 판다 - 1937번

    내 코드 package com.company; import java.io.*; import java.util.*; public class Main { static int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; static int[][] arr, dp; static int N, answer; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; N = Integer.parseInt(br.readLine()); arr = new int[N..

    가스관 - 2931번

    가스관 - 2931번

    package com.company; import java.io.*; import java.util.*; public class Main { // 방향 (인덱스 0 -> 아래, 1 -> 위, 2 -> 오른쪽, 3 -> 왼쪽) static int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; // 아래쪽, 위쪽, 오른쪽, 왼쪽 순서대로 가능한 블록 static char[][] block = {{'|', '+', '2', '3'}, {'|', '+', '1', '4'}, {'-', '+', '3', '4'}, {'-', '+', '1', '2'}}; // 숫자 블록으로 바뀌는 방향 (-1은 못가는 방향) // 블록 1 이면 { 위에서 아래로 못들어옴 (-1), // 아래에서 ..

    구슬 탈출2 - 13460번

    구슬 탈출2 - 13460번

    내 코드 package com.company; import java.io.*; import java.util.*; public class Main { static int N, M, answer; static int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; static boolean[][][][] visited; static char[][] arr; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.rea..

    통나무 옮기기

    통나무 옮기기

    내 코드 package com.company; 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)); StringTokenizer st = null; int answer = 0; int N = Integer.parseInt(br.readLine()); char[][] arr = new char[N][N]; ArrayList listB = new ArrayList(); // 초기 통나무 ArrayList listE = ne..

    2048 (Easy) - 12100번

    2048 (Easy) - 12100번

    내 코드 package com.company; import java.io.*; import java.util.*; public class Main { static int N, answer; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; N = Integer.parseInt(br.readLine()); answer = 0; int[][] arr = new int[N][N]; for (int i = 0; i < N; i++) { st = new StringTokenize..

    연구소 - 14502번

    연구소 - 14502번

    내 코드 package com.company; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0,..

    동작 그만. 밑장 빼기냐? - 20519번

    동작 그만. 밑장 빼기냐? - 20519번

    풀이 방법 짝수, 홀수 번호인 카드를 나눠서 저장했다. 나에게 줄 차례에 밑장빼기 하는 경우와 상대방에게 줄 차례에 밑장 빼기 하는 경우 이 두가지를 생각해서 풀이 하면 된다. 내 코드 package com.company; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(s..

    강의실 배정 - 11000번

    강의실 배정 - 11000번

    내 코드 package com.company; import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; int N = Integer.parseInt(br.readLine()); int[][] arr = new int[N][2]; int answer = 0; int count = 0; for (int i = 0; i < N; i++) { st = new StringTokenizer..

    찾기 - 1786번

    찾기 - 1786번

    KMP 알고리즘 문제 내 코드 package com.company; 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)); String T = br.readLine(); String P = br.readLine(); int lenT = T.length(); int lenP = P.length(); int[] arr = new int[P.length()]; // 부분일치 테이블 (접미사, 접두사가 같은 최대 크기) int ..

    치킨 배달 - 15686번

    치킨 배달 - 15686번

    내 코드 import java.io.*; import java.util.*; public class Main { static int N, M, min; static ArrayList home, chicken; static int[] distance; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); N = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextT..