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
- {
- 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 total = 0;
- int x = int.Parse(indataArray[0]) - 1;
- int y = int.Parse(indataArray[1]) - 1;
- int k = int.Parse(indataArray[2]);
- String[,] rutnät = new String[x + 1, y + 1];
- Boolean[,] redanV = new bool[x + 1, y + 1];
- redanV[0, 0] = true;
- for (int i = 0; i < y + 1; i++)
- {
- indata = Console.ReadLine();
- for (int j = 0; j < x + 1; 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();
- total = cur.ln;
- 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 + 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.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;
- }
- }
- if (redanV[x, y] == false)
- {
- Console.WriteLine("nej");
- }
- else
- {
- Console.WriteLine(total);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment