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
- Tostring 사용법
- 호스트
- C# Contains
- 네트워크
- 서브넷 마스크
- List 추가
- DP
- 알고리즘
- IP주소
- List 정렬
- Visual Studio
- BFS
- 기본 게이트웨이
- 네트워크 용어
- InsertRange
- list 사용법
- 서브넷
- c#
- List 제거
- TCP/IP
- OSI 3계층
- List 찾기
- AddRange
- Parse 사용법
- C++
- 호스트 주소
- C# Find
- 백준
- c# list
- list
Archives
- Today
- Total
CodeLabs
[백준 / C#] 1697 : 숨바꼭질 본문
using System;
using System.Collections.Generic;
using System.Linq;
struct Locate
{
public int location, time;
public Locate(int location,int time)
{
this.location = location;
this.time = time;
}
}
class Program
{
static int[] N_K = Console.ReadLine().Split().Select(int.Parse).ToArray();
static int n = N_K[0], k = N_K[1];
static bool[] visited = new bool[100001];
static Queue<Locate> lot = new Queue<Locate>();
static bool Confirm(int n)
{
if (n < 0 || n > 100000 || visited[n])
return false;
return true;
}
static void BFS()
{
visited[n] = true;
lot.Enqueue(new Locate(n,0));
while (lot.Count != 0)
{
int location = lot.Peek().location;
int time = lot.Peek().time;
lot.Dequeue();
if (location == k)
{
Console.WriteLine(time);
break;
}
if (Confirm(location - 1))
{
visited[location - 1] = true;
lot.Enqueue(new Locate(location - 1, time + 1));
}
if(Confirm(location +1))
{
visited[location + 1] = true;
lot.Enqueue(new Locate(location + 1, time + 1));
}
if(Confirm(location*2))
{
visited[location * 2] = true;
lot.Enqueue(new Locate(location * 2, time + 1));
}
}
}
static void Main(string[] args)
{
BFS();
}
}
'백준 > 1000 ~' 카테고리의 다른 글
[백준 / C#] 1927 : 최소 힙 (0) | 2023.07.24 |
---|---|
[백준 / C++] 1764 : 듣보잡 (0) | 2023.07.21 |
[백준 / C++] 1620 : 나는야 포켓몬 마스터 이다솜 (0) | 2023.07.15 |
[백준 / C#] 1541 : 잃어버린 괄호 (0) | 2023.07.13 |
[백준 / C#] 1463 : 1로 만들기 (0) | 2023.07.11 |