Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Eldberget
- {
- public class Node
- {
- public int x;
- public int y;
- public int ln;
- }
- class Program
- {
- static void Main(string[] args)
- {
- Node p = new Node();
- p.x = 0;
- p.y = 0;
- p.ln = 0;
- string indata = Console.ReadLine();
- string[] indataArray = indata.Split();
- int x = int.Parse(indataArray[0]);
- int y = int.Parse(indataArray[1]);
- int k = int.Parse(indataArray[2]);
- String[,] rutnät = new String[x, y];
- Boolean[,] redanV = new bool[x, y];
- for (int i = 0; i < y; i++)
- {
- indata = Console.ReadLine();
- for (int j = 0; j < x; j++)
- {
- rutnät[j, i] = indata[j].ToString();
- }
- }
- Queue<Node> kö = new Queue<Node>();
- kö.Enqueue(p);
- while (kö.Count > 0)
- {
- Node cur = kö.Dequeue();
- if (cur.x + 1 <= x && rutnät[cur.x + 1, cur.y] != "#" && redanV[cur.x + 1, cur.y] == false)
- {
- Node next = new Node();
- next.x = cur.x + 1;
- next.y = cur.y;
- next.ln = cur.ln + 1;
- kö.Enqueue(next);
- redanV[cur.x + 1, cur.y] = true;
- }
- if (cur.y + 1 <= y && rutnät[cur.x, cur.y + 1] != "#" && redanV[cur.x, cur.y] == false)
- {
- Node next = new Node();
- next.x = cur.x;
- next.y = cur.y + 1;
- next.ln = cur.ln + 1;
- kö.Enqueue(next);
- redanV[cur.x, cur.y + 1] = true;
- }
- if (cur.y - 1 <= 0 && rutnät[cur.x, cur.y - 1] != "#" && redanV[cur.x, cur.y - 1] == false)
- {
- Node next = new Node();
- next.x = cur.x;
- next.y = cur.y - 1;
- next.ln = cur.ln + 1;
- kö.Enqueue(next);
- redanV[cur.x, cur.y - 1] = true;
- }
- if (cur.x - 1 <= 0 && rutnät[cur.x - 1, cur.y] != "#" && redanV[cur.x - 1, cur.y] == false)
- {
- Node next = new Node();
- next.x = cur.x - 1;
- next.y = cur.y;
- next.ln = cur.ln + 1;
- kö.Enqueue(next);
- redanV[cur.x - 1, cur.y] = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment