Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- list 사용법
- C# Find
- Visual Studio
- TCP/IP
- List 제거
- 네트워크 용어
- InsertRange
- C# Contains
- C++
- AddRange
- Parse 사용법
- List 정렬
- 네트워크
- 호스트 주소
- 서브넷
- 기본 게이트웨이
- 서브넷 마스크
- Tostring 사용법
- IP주소
- 호스트
- List 찾기
- c#
- list
- 알고리즘
- List 추가
- 백준
- BFS
- OSI 3계층
- c# list
- DP
Archives
- Today
- Total
CodeLabs
[백준 / C#] 2178 : 미로탐색 본문
using System;
using System.Collections.Generic;
using System.Linq;
namespace _2178
{
class Pair
{
public Pair(int first_, int second_)
{
first = first_;
second = second_;
}
public int second { get; set; }
public int first { get; set; }
}
class Program
{
static int n, m;
static int[] dx = { 0, 1, 0, -1 }, dy = { -1, 0, 1, 0 };
static int[,] check = new int[100, 100];
static string[] input = new string[100];
static bool[,] vi = new bool[100,100];
static void BFS(int i, int j)
{
vi[i, j] = true;
Pair pair = new Pair(i, j);
Queue<Pair> q = new Queue<Pair>();
q.Enqueue(pair);
while (!q.Count.Equals(0))
{
int x = q.Peek().second;
int y = q.Peek().first;
q.Dequeue();
for (int k = 0; k < 4; k++)
{
int newY = y + dy[k];
int newX = x + dx[k];
if (0 <= newY && newY < n && 0 <= newX && newX < m)
{
if ((input[newY])[newX] == '1' && !vi[newY, newX]&& check[newY,newX] ==0)
{
check[newY, newX] = check[y, x] + 1;
vi[newY, newX] = true;
q.Enqueue(new Pair(newY,newX));
}
}
}
}
}
static void Input()
{
int[] y_x = Console.ReadLine().Split().Select(int.Parse).ToArray();
n = y_x[0]; m = y_x[1];
for (int i = 0; i < n; i++) input[i] = Console.ReadLine();
BFS(0, 0);
Console.WriteLine(check[n - 1, m - 1] + 1);
}
static void Solve()
{
Input();
}
static void Main(string[] args)
{
Solve();
}
}
}
'백준 > 1000 ~' 카테고리의 다른 글
[백준 / C#] 2606 : 바이러스 (0) | 2023.08.02 |
---|---|
[백준 / C#] 2579 : 계단 오르기 (0) | 2023.07.30 |
[백준 / C#] 1931 : 회의실 배정 (0) | 2023.07.26 |
[백준 / C#] 1927 : 최소 힙 (0) | 2023.07.24 |
[백준 / C++] 1764 : 듣보잡 (0) | 2023.07.21 |