diff --git "a/source/KJH/\352\267\270\353\236\230\355\224\204\355\203\220\354\203\211/220524/bj3184.md" "b/source/KJH/\352\267\270\353\236\230\355\224\204\355\203\220\354\203\211/220524/bj3184.md" new file mode 100644 index 0000000..a19b6fa --- /dev/null +++ "b/source/KJH/\352\267\270\353\236\230\355\224\204\355\203\220\354\203\211/220524/bj3184.md" @@ -0,0 +1,83 @@ +## 양 + +dfs/bfs 다시 시작하겠습니다.. + +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class Main{ + static int R,C; + static char[][] maps; + static boolean[][] visited; + static int dx[] = {1,0,-1,0}; + static int dy[] = {0,1,0,-1}; + static Queue queue = new LinkedList<>(); + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + visited =new boolean[R][C]; + maps = new char[R][C]; + + int vcount = 0; + int ocount =0; + for(int i=0; i=0 && nX < R && nY >=0 && nY < C){ + if(maps[nX][nY] == 'V' && !visited[nX][nY]){ + queue.add(new int[]{nX,nY}); + vistied[nX][nY] = true; + vcount +=1; + } + else if(maps[nX][nY] == '#'){ + continue; + } + else if(maps[nX][nY] == '.' && !visited[nX][nY]){ + queue.add(new int[]{nX,nY}); + visited[nX][nY] = true; + } + else if(maps[nX][nY] == 'O'){ + ocount += 1; + } + } + + } + } + } +} +``` diff --git "a/source/KJH/\352\267\270\353\236\230\355\224\204\355\203\220\354\203\211/220525/bj2606.md" "b/source/KJH/\352\267\270\353\236\230\355\224\204\355\203\220\354\203\211/220525/bj2606.md" new file mode 100644 index 0000000..6d1bb6b --- /dev/null +++ "b/source/KJH/\352\267\270\353\236\230\355\224\204\355\203\220\354\203\211/220525/bj2606.md" @@ -0,0 +1,57 @@ +## 바이러스 + +예전에 풀었던 문제라 쉬웠따 +bfs지만, queue를 사용하지 않고 재귀를 통해 풀었다. + +```java + +import java.io.BufferedReader; +import java.io.IOException; +import java.util.StringTokenizer; +import java.util.*; +import java.io.*; + +public class Main{ + + static int n,m; + static ArrayList[] arrayList; + static boolean[] visited; + static int count=0; + public static void main(String[] args)throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + n = Integer.parseInt(br.readLine()); //컴퓨터 수 + m = Integer.parseInt(br.readLine()); //컴퓨터 번호 쌍 + arrayList = new ArrayList[n+1]; + visited = new boolean[n+1]; + + for(int i=1; i<=n; i++){ + arrayList[i] = new ArrayList(); + } + + for(int i=0; i[] arr; + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + arr = new ArrayList[N+1]; + visited = new boolean[N+1]; + for(int i=1; i arrlist = new ArrayList<>(); + + for(int i=0; i queue = new LinkedList<>(); + visited[p.r][p.c] = true; + queue.add(p); + + while(!queue.isEmpty()){ + Point tmp = queue.poll(); + int tmpX = tmp.r; + int tmpY = tmp.c; + int cnt = tmp.cnt; + + if(tmpX == goal.r && tmpY == goal.c){ + System.out.println(tmp.cnt); + return; + } + for(int i=0; i<8; i++){ + int nx = tmpX + dx[i]; + int ny = tmpY + dy[i]; + + if(nx >= 0 && nx < l && ny>= 0 && ny< l && !visited[nx][ny]){ + queue.add(new Point(nx, ny, cnt+1)); + visited[nx][ny] = true; + } + } + } + } + + static class Point{ + int r, c, cnt; + + public Point(int r, int c, int cnt){ + this.r = r; + this.c = c; + this.cnt = cnt; + } + } +} + +```