diff --git "a/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-11085] \352\265\260\354\202\254 \354\235\264\353\217\231.java" "b/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-11085] \352\265\260\354\202\254 \354\235\264\353\217\231.java" new file mode 100644 index 00000000..8babdc8b --- /dev/null +++ "b/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-11085] \352\265\260\354\202\254 \354\235\264\353\217\231.java" @@ -0,0 +1,68 @@ +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 = new StringTokenizer(br.readLine()); + + int p = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + + st = new StringTokenizer(br.readLine()); + int s = Integer.parseInt(st.nextToken()); + int e = Integer.parseInt(st.nextToken()); + + List[] graph = new ArrayList[p]; + for(int i=0; i(); + } + + for(int i=0; i pq = new PriorityQueue<>((o1, o2) -> -Integer.compare(o1[1], o2[1])); + boolean[] visited = new boolean[p]; + pq.offer(new int[] {s, Integer.MAX_VALUE}); + + while(!pq.isEmpty()) { + int[] info = pq.poll(); + int current = info[0]; + + if(current == e) { + System.out.println(info[1]); + return; + } + + if(visited[current]) continue; + visited[current] = true; + + for(Edge edge : graph[current]) { + if(visited[edge.to]) continue; + pq.offer(new int[] {edge.to, Math.min(info[1], edge.weight)}); + } + } + + System.out.println(0); + } + + public static class Edge{ + int to; + int weight; + + public Edge(int to, int weight) { + this.to = to; + this.weight = weight; + } + } +} diff --git "a/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-15898] \355\224\274\354\225\204\354\235\230 \354\225\204\355\213\200\353\246\254\354\227\220 -\354\213\240\353\271\204\355\225\234 \353\214\200\355\232\214\354\235\230 \354\227\260\352\270\210\354\210\240\354\202\254-.java" "b/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-15898] \355\224\274\354\225\204\354\235\230 \354\225\204\355\213\200\353\246\254\354\227\220 -\354\213\240\353\271\204\355\225\234 \353\214\200\355\232\214\354\235\230 \354\227\260\352\270\210\354\210\240\354\202\254-.java" new file mode 100644 index 00000000..a1fbd159 --- /dev/null +++ "b/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-15898] \355\224\274\354\225\204\354\235\230 \354\225\204\355\213\200\353\246\254\354\227\220 -\354\213\240\353\271\204\355\225\234 \353\214\200\355\232\214\354\235\230 \354\227\260\352\270\210\354\210\240\354\202\254-.java" @@ -0,0 +1,176 @@ +import java.io.*; +import java.util.*; + +public class Main { + private static final int ORDER_SIZE = 3; + private static final int MATTER_SIZE = 4; + private static final int KILN_SIZE = 5; + + private static int n; + private static Matter[][] matters; + private static int[][] order; + private static int result; + private static Matter kiln; + private static int[][] position = {{0,0},{0,1},{1,0},{1,1}}; + private static boolean[] visited; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + n = Integer.parseInt(br.readLine()); + matters = new Matter[n][4]; + for(int i=0; i 9) value = 9; + kiln.value[ni][nj] = value; + + //원소 변경 + if(matter.element[i][j] == 'W') continue; + kiln.element[ni][nj] = matter.element[i][j]; + } + } + } + + private static int calcul() { + int r=0, b=0, g=0, y=0; + + for(int i=0; i=n || ny<0 || ny>=n || board[nx][ny].type == 2) { + //방향전환하고 + piece.changeDir(); + //이동할 곳 + nx = piece.x + d[piece.dir][0]; + ny = piece.y + d[piece.dir][1]; + + //이동할 곳이 다시 보드 밖이거나 파란색일 경우 이동하지 않음 + if(nx<0 || nx>=n || ny<0 || ny>=n || board[nx][ny].type == 2) continue; + } + //흰색이거나 빨간색인 경우 이동함 + //말 아래에 말이 있던 경우에는 연결 끊기 + if(piece.down != null) { + piece.down.up = null; + piece.down = null; + } + + //움직이는 말이 보드에 직접 맞닿아 있는 말이라면 기존 칸 위에는 말이 없음 + if(board[piece.x][piece.y].bottom == piece) + board[piece.x][piece.y].bottom = null; + + //말 이동 + piece.x = nx; + piece.y = ny; + piece.update(); + + //빨간색이고 말 위에 말이 있다면 + if(board[nx][ny].type == 1 && piece.up != null) { + //뒤집음 + Piece bottom = piece; + while(piece != null) { + Piece temp = piece.up; + piece.up = piece.down; + piece.down = temp; + bottom = piece; + piece = temp; + } + + piece = bottom; + } + + //해당 칸에 말이 없을 경우 + if(board[nx][ny].bottom == null) { + board[nx][ny].bottom = piece; + } + + //해당 칸에 말이 있을 경우 + else { + Piece top = board[nx][ny].bottom.getTop(); + piece.down = top; + top.up = piece; + } + + //개수 체크 + if(board[nx][ny].bottom.size() >= 4) { + System.out.println(count); + return; + } + } + } + + System.out.println(-1); + } + + private static class Cell{ + int type; + Piece bottom; + + public Cell(int type) { + this.type = type; + } + + @Override + public String toString() { + String sType = "W"; + if(type == 1) sType = "R"; + else if(type == 2) sType = "B"; + + String sbottom = bottom == null ? "x" : bottom.toString(); + + return "["+sType+"/"+sbottom+"]"; + } + } + + private static class Piece{ + int num; + int x, y; + int dir; + Piece up, down; + + public Piece(int num, int x, int y, int dir) { + this.num = num; + this.x = x; + this.y = y; + this.dir = dir; + } + + public int size() { + Piece next = this; + int count = 1; + while(next.up != null) { + next = next.up; + count++; + } + return count; + } + + public Main.Piece getTop() { + Piece next = this; + while(next.up != null) { + next = next.up; + } + return next; + } + + public void update() { + Piece next = this.up; + while(next != null) { + next.x = this.x; + next.y = this.y; + next = next.up; + } + } + + public void changeDir() { + switch(dir) { + case 0: dir = 1; break; + case 1: dir = 0; break; + case 2: dir = 3; break; + case 3: dir = 2; break; + } + } + + public String getSDir() { + String sdir = "→"; + if(dir == 1) sdir = "←"; + else if(dir == 2) sdir = "↑"; + else if(dir == 3) sdir = "↓"; + return sdir; + } + + @Override + public String toString() { + String snum = num+"("+getSDir()+")"; + Piece next = this.up; + while(next != null) { + snum += ","+next.num+"("+next.getSDir()+")"; + next = next.up; + } + return snum; + } + } +} diff --git "a/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-8980] \355\203\235\353\260\260.java" "b/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-8980] \355\203\235\353\260\260.java" new file mode 100644 index 00000000..c96f42c6 --- /dev/null +++ "b/\354\234\240\353\263\221\352\267\234_17\354\243\274\354\260\250/[BOJ-8980] \355\203\235\353\260\260.java" @@ -0,0 +1,55 @@ +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 = new StringTokenizer(br.readLine()); + + int n = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + + List order = new ArrayList<>(); + + int m = Integer.parseInt(br.readLine()); + for(int i=0; i Integer.compare(o1[1], o2[1])); + + //트럭에 실은 박스들 + int[] village = new int[n+1]; + + //트럭 출발 + int result = 0; + for(int idx=0; idx