그래프 10

[B21278][호석이 두 마리 치킨][java]

https://www.acmicpc.net/problem/21278 21278번: 호석이 두 마리 치킨 위의 그림과 같이 1번과 2번 건물에 치킨집을 짓게 되면 1번부터 5번 건물에 대해 치킨집까지의 왕복 시간이 0, 0, 2, 2, 2 로 최소가 된다. 2번과 3번 건물에 지어도 동일한 왕복 시간이 나오지만 더 www.acmicpc.net 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static int n, m, min; static int a, b; static int[][] arr; public stat..

BAEKJOON/Java 2023.10.11

[B7576][토마토][C++]

보관 후, 하루가 지나면 익은 토마토의 인접한 곳에 익지 않은 토마토들은 익게 됨 (인접한 곳 - 왼, 오, 앞, 뒤) 혼자 저절로 익는 경우는 없음 며칠이 지나면 다 익게 되는가? m,n - 상자 가로, 세로 1 - 익은 토마토 0 - 익지 않은 토마토 -1 - 토마토가 들어있지 않음 최소 날짜 출력 (모든 토마토 익어있음 = 0, 모두 익지 못함 = -1) #include #include using namespace std; int m, n, cnt; int map[1001][1001]; bool isVisit[1001][1001]; int dr[4] = { -1,1,0,0 }; int dc[4] = { 0,0,-1,1 }; queue Q; int main(void) { ios::sync_with_s..

BAEKJOON/C++ 2021.06.10

[B1012][유기농 배추][C++]

#include #include using namespace std; //가로길이 m = 열, 세로길이 n = 행 //BFS(Breadth-first search) : 너비우선탐색 - 인접한 노드 먼저(얕은 노드 -> 깊은 노드) //DFS(Depth-First Search) : 깊이우선탐색 - //큐 - FIFO 이용 //1. 타겟 발견 //2. 맵 벗어났나 //3. 이미 방문한 타겟인가 int t; int m, n, k; int map[50][50]; bool visit[50][50]; int result; queue Q; int dr[4] = { -1,1,0,0 }; int dc[4] = { 0,0,-1,1 }; int main() { cin >> t; while (t--) { cin >> m >>..

BAEKJOON/C++ 2021.06.07