diff --git a/README.md b/README.md index 984b1d1..2b83dd9 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,12 @@ - + + + + + + diff --git "a/src/ji/week1/day1/P_\352\262\275\353\241\234\354\260\276\352\270\260_11403.java" "b/src/ji/week1/day1/P_\352\262\275\353\241\234\354\260\276\352\270\260_11403.java" index f4857c1..71c74ea 100644 --- "a/src/ji/week1/day1/P_\352\262\275\353\241\234\354\260\276\352\270\260_11403.java" +++ "b/src/ji/week1/day1/P_\352\262\275\353\241\234\354\260\276\352\270\260_11403.java" @@ -1,5 +1,54 @@ -package ji.week1.day1; +package com.solve.backjun; -public class P_경로찾기_11403 { +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +public class Main { + public static int[][] map; + public static int N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); +// BufferedReader br = new BufferedReader(new FileReader("input.txt")); + + // 수업시간에 배웠던 내용 + // readLine()으로 받아올 String 객체를 기본형 타입인 int와 형변환이 안되므로 + // Wrapper Class 사용 (Integer) ==> int 타입 변수를 객체로 포장함 + N = Integer.parseInt(br.readLine()); + map = new int[N][N]; + + for (int h=0; h 키워드 => 플로이드 => 공식 Dab = min(Dab, Dak+Dkb) + for (int k=0; k k -> b) 경로가 없을 때 값이 너무커져서 걸러지는데, + // 여긴 간선이 없을 땐 0이라서 공식을 사용하면 모든 자리에 값이 들어가버려 원인을 찾는 데 시간이 걸렸다. + // 3중 반복문 변수 순서도 주의할 것 (k a b) + + private static void print() { + StringBuilder sb = new StringBuilder(); + for (int h=0; h 1; i--) { + sum = sum * i; + // 오버플로우를 방지하는 것이 문제의 핵심 + // 뒤에 0이 있는 숫자는 무엇을 곱해도 0이 유지가 되므로 + // 0을 따로 카운트하고 자리수를 줄인다. + while(sum > 0) { + int temp = sum % 10; + if (temp == 0) { + zero_count++; + sum = sum / 10; + } else { + break; + } + } + if (sum==0) { // 0 곱해지는 현상 방지 (ex : 100!) + sum = 1; + } else if(sum > 1000000) { // 단순 숫자로만 자리수를 채운다면 4자리만큼만 잘라낸다. + sum = sum % 10000; + } + } + return zero_count; + } +} diff --git "a/src/ji/week1/day1/week2/day1/P_\353\261\200_3190.java" "b/src/ji/week1/day1/week2/day1/P_\353\261\200_3190.java" new file mode 100644 index 0000000..237590f --- /dev/null +++ "b/src/ji/week1/day1/week2/day1/P_\353\261\200_3190.java" @@ -0,0 +1,101 @@ +import java.awt.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Main { + public static int[][] map; + public static int time =0; + public final static int[][] direct = {{0,1},{1,0},{0,-1},{-1,0}}; + public static int now_direct = 0; + public static int now_h = 0; + public static int now_w = 0; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + HashMap hm = new HashMap<>(); + + int N = Integer.parseInt(br.readLine()); + map = new int[N][N]; + // snake queue + Queue queue = new LinkedList<>(); + + int N_apple = Integer.parseInt(br.readLine()); + for (int i = 0; i < N_apple; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int temp_h = Integer.parseInt(st.nextToken()); + int temp_w = Integer.parseInt(st.nextToken()); + map[temp_h-1][temp_w-1] = 2; + } + + int N_angle = Integer.parseInt(br.readLine());; + for (int i = 0; i < N_angle; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int key = Integer.parseInt(st.nextToken()); + String value = st.nextToken(); + hm.put(key, value); + } + + map[0][0] = 1; + queue.add(new Point(0,0)); + + + while (true) { + time++; + int next_h = now_h + direct[now_direct][0]; + int next_w = now_w + direct[now_direct][1]; + if(next_h >= N || next_h < 0 || next_w >= N || next_w < 0) { + break; + } + + if (map[next_h][next_w] == 2) { // 사과 좌표로 이동 + now_h = next_h; + now_w = next_w; + queue.add(new Point(next_h,next_w)); + map[next_h][next_w] = 1; + } else if (map[next_h][next_w] == 1) { // 본인 꼬리 밟음 + break; + } else { // 빈 공간으로 이동 + map[next_h][next_w] = 1; + now_h = next_h; + now_w = next_w; + Point p = queue.poll(); + map[p.x][p.y] = 0; + queue.add(new Point(next_h,next_w)); + } + + if (hm.containsKey(time)) { + String move_to = hm.get(time); + if (move_to.equals("D")) { + now_direct++; + } else { + now_direct--; + } + if (now_direct >= 4) { + now_direct = now_direct % 4; + } + if (now_direct < 0) { + now_direct += 4; + } + } + } + + System.out.println(time); + + } + +// public static void print(int n) { +// StringBuilder sb = new StringBuilder(); +// for (int i=0; i 1; i--) { + sum = sum * i; + // 오버플로우를 방지하는 것이 문제의 핵심 + // 뒤에 0이 있는 숫자는 무엇을 곱해도 0이 유지가 되므로 + // 0을 따로 카운트하고 자리수를 줄인다. + while(sum > 0) { + int temp = sum % 10; + if (temp == 0) { + zero_count++; + sum = sum / 10; + } else { + break; + } + } + if (sum==0) { // 0 곱해지는 현상 방지 (ex : 100!) + sum = 1; + } else if(sum > 1000000) { // 단순 숫자로만 자리수를 채운다면 4자리만큼만 잘라낸다. + sum = sum % 10000; + } + } + return zero_count; + } +} diff --git "a/src/ji/week1/day3/P_\353\266\200\353\205\200\355\232\214\354\236\245\354\235\264 \353\220\240\355\205\214\354\225\274_2775.java" "b/src/ji/week1/day3/P_\353\266\200\353\205\200\355\232\214\354\236\245\354\235\264 \353\220\240\355\205\214\354\225\274_2775.java" new file mode 100644 index 0000000..27f3573 --- /dev/null +++ "b/src/ji/week1/day3/P_\353\266\200\353\205\200\355\232\214\354\236\245\354\235\264 \353\220\240\355\205\214\354\225\274_2775.java" @@ -0,0 +1,44 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Main { + public static int a; + public static int b; + public static int[] room; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + + for (int t = 0; t < T; t++) { + a = sc.nextInt(); + b = sc.nextInt(); + room = new int[b]; + for (int i = 0; i < b; i++) { + room[i] = i+1; + } + + recur(1); + System.out.println(room[b-1]); + + } + return; + } + + public static void recur(int floor) { + + for (int i = b-1; i >= 0; i--) { + for (int j = 0; j < i; j++) { + room[i] += room[j]; + } + } + + if (floor == a) { + return; + } + floor++; + recur(floor); + return; + } + +}