From 5c5507443e2796a87d6036f4ef2365914ef08457 Mon Sep 17 00:00:00 2001 From: monsileI Date: Fri, 16 Sep 2022 20:05:52 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=ED=92=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ssafy_avanced_study/no_1249.java | 101 ++++++++++++------ Basic_Of_Algorithm/src/swea/no_1244.java | 68 ++++++++++++ Basic_Of_Algorithm/src/swea/no_1289.java | 53 +++++++++ Basic_Of_Algorithm/src/test/no_13.java | 54 ++++++++++ 4 files changed, 241 insertions(+), 35 deletions(-) create mode 100644 Basic_Of_Algorithm/src/swea/no_1244.java create mode 100644 Basic_Of_Algorithm/src/swea/no_1289.java create mode 100644 Basic_Of_Algorithm/src/test/no_13.java diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java index 8a703e1..5741327 100644 --- a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java @@ -11,38 +11,69 @@ public class no_1249 { - public static void main(String[] args) throws Exception { - - - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - int T; - T=Integer.parseInt(br.readLine()); - - for(int test_case = 1; test_case <= T; test_case++){ - - int n = Integer.parseInt(br.readLine()); - - int [][]map = new int[n+2][2]; - boolean[] check = new boolean[n+2]; - int[]result = new int[n+2]; - - int min = Integer.MAX_VALUE; - map[0][0] = Integer.parseInt(br.readLine()); - map[0][1] = Integer.parseInt(br.readLine()); - map[n+1][0] = Integer.parseInt(br.readLine()); - map[n+1][1] = Integer.parseInt(br.readLine()); - - for(int i=0;i<=n;i++) { - map[i][0] = Integer.parseInt(br.readLine()); - map[i][1] = Integer.parseInt(br.readLine()); - - } - - - - - } - - } - -} \ No newline at end of file + public static void main(String args[]) throws Exception + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T; + T=Integer.parseInt(br.readLine()); + + for(int test_case = 1; test_case <= T; test_case++){ + + int size =Integer.parseInt(br.readLine()); + + int[][]map = new int[size][size]; + + int answer = Integer.MAX_VALUE; + + + for(int i=0;i q = new LinkedList<>(); + + int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; + int[][]temp = new int[size][size]; + boolean[][]visited = new boolean[size][size]; + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int []c = q.poll(); + int i = c[0]; + int j = c[1]; + + if(i==size-1 && j==size-1) { + answer = Math.min(answer, temp[i][j]); + continue; + } + if(answer<=temp[i][j]) continue; + + for(int d=0;d<4;d++) { + int ni = i + mov[d][0]; + int nj = j + mov[d][1]; + + if(ni<0 || nj<0|| size-1 temp[i][j] + map[ni][nj]) { + visited[ni][nj] = true; + temp[ni][nj] = temp[i][j] + map[ni][nj]; + q.add(new int[] {ni,nj}); + } + + } + + } + + System.out.println("#"+test_case+" "+answer); + + + + } + + } + + } \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/swea/no_1244.java b/Basic_Of_Algorithm/src/swea/no_1244.java new file mode 100644 index 0000000..7e37ebf --- /dev/null +++ b/Basic_Of_Algorithm/src/swea/no_1244.java @@ -0,0 +1,68 @@ +package swea; + +import java.util.Scanner; + +public class no_1244 { + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + int size = sc.nextInt(); + + int[]arr = new int[size]; + + for(int i=0;i map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Leave")) continue; + + String nick = temp[2]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } +}