smooth waters run deep

BFS/DFS 14

1707_이분 그래프 (JAVA)

1707번: 이분 그래프 입력은 여러 개의 테스트 케이스로 구성되어 있는데, 첫째 줄에 테스트 케이스의 개수 K(2≤K≤5)가 주어진다. 각 테스트 케이스의 첫째 줄에는 그래프의 정점의 개수 V(1≤V≤20,000)와 간선의 개수 www.acmicpc.net import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class Main { static int n; static int m; static ArrayList[] graph; static int[] color; static boolean flag = false; pub..

1d-1c/BOJ 2020.12.03

14888_연산자 끼워넣기 (JAVA)

14888번: 연산자 끼워넣기 첫째 줄에 수의 개수 N(2 ≤ N ≤ 11)가 주어진다. 둘째 줄에는 A1, A2, ..., AN이 주어진다. (1 ≤ Ai ≤ 100) 셋째 줄에는 합이 N-1인 4개의 정수가 주어지는데, 차례대로 덧셈(+)의 개수, 뺄셈(-)의 개수, www.acmicpc.net ① 순열 이용 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main { static List calList = new ArrayList(); static int[] ..

1d-1c/BOJ 2020.11.29

14500_테트로미노 (JAVA)

14500번: 테트로미노 폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다. 정사각형은 서로 겹치면 안 된다. 도형은 모두 연결되어 있어야 한다. 정사각형의 변 www.acmicpc.net import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int n; static int m; static int[][] map; static boolean[][] visited; static int[] dx = {1,-1,0,0}; static int[] dy = {0,0,1,-1}; static..

1d-1c/BOJ 2020.11.23

7562_나이트의 이동 (JAVA)

7562번: 나이트의 이동 체스판 위에 한 나이트가 놓여져 있다. 나이트가 한 번에 이동할 수 있는 칸은 아래 그림에 나와있다. 나이트가 이동하려고 하는 칸이 주어진다. 나이트는 몇 번 움직이면 이 칸으로 이동할 수 www.acmicpc.net import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Main { static class XY{ int x; int y; public XY(int x, int y){ this.x = x; this.y = y; } } static int[] dx = {-2, -2, -1, 1, 2, 2, 1, -1}; static int[] dy = {-1, 1..

1d-1c/BOJ 2020.11.18

10026_적록색약 (JAVA)

10026번: 적록색약 적록색약은 빨간색과 초록색의 차이를 거의 느끼지 못한다. 따라서, 적록색약인 사람이 보는 그림은 아닌 사람이 보는 그림과는 좀 다를 수 있다. 크기가 N×N인 그리드의 각 칸에 R(빨강), G(초록) www.acmicpc.net import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; public class Main { static class XY{ int x; int y; public XY(int x, int y){ this.x = x; this.y = y; } } static int N; static int[] dx = {-1..

1d-1c/BOJ 2020.11.16

4963_섬의 개수 (JAVA) (C++)

4963번: 섬의 개수 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스의 첫째 줄에는 지도의 너비 w와 높이 h가 주어진다. w와 h는 50보다 작거나 같은 양의 정수이다. 둘째 줄부터 h개 줄에는 지도 www.acmicpc.net [C++] - ① BFS #include #include //memset #include using namespace std; int w=1; int h=1; int map[51][51] = {0,}; bool visited[51][51] = {false}; int ans = 0; struct XY{ int x; int y; }; int dx[] = {-1,-1,-1,0,0,1,1,1}; int dy[] = {-1,0,1,-1,1,-1,0,1}; void ..

1d-1c/BOJ 2020.11.09

2606_바이러스 (JAVA)

2606번: 바이러스 첫째 줄에는 컴퓨터의 수가 주어진다. 컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. 둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어 www.acmicpc.net import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static int N; static int M; static int[][] com; static int[] visited; static int ans=0; public static void main(String[] args) { Scanner sc = new Scanner(System.in)..

1d-1c/BOJ 2020.10.23

1697_숨바꼭질 (JAVA)

1697번: 숨바꼭질 수빈이는 동생과 숨바꼭질을 하고 있다. 수빈이는 현재 점 N(0 ≤ N ≤ 100,000)에 있고, 동생은 점 K(0 ≤ K ≤ 100,000)에 있다. 수빈이는 걷거나 순간이동을 할 수 있다. 만약, 수빈이의 위치가 X일 www.acmicpc.net import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static int N; static int K; static int[] visited = new int[100001]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); ..

1d-1c/BOJ 2020.10.23

1012_유기농 배추 (JAVA)

1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net import java.util.*; import java.lang.*; import java.io.*; class Main { static int T; static int M, N, K; static int[] dx = {-1,1,0,0}; static int[] dy = {0,0,-1,1}; static int[][] map; static int[][] visited; static int ans; static class XY{ int x, y; public XY(int x..

1d-1c/BOJ 2020.09.11