Program.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using static D24._1.Program;
  6. namespace D24._2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. var file = File.ReadAllText(args[0]).Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  13. var poi = new Dictionary<int, (int x, int y)>();
  14. var map = ParseMap(file, poi);
  15. var perm = GetPermutations(poi.Keys.OrderBy(p => p).Skip(1), poi.Count - 1);
  16. int minStep = int.MaxValue;
  17. foreach (var p in perm)
  18. {
  19. var current = 0;
  20. int step = 0;
  21. foreach (var destination in p.Append(0))
  22. {
  23. step += Solve(map, poi[current], poi[destination]);
  24. current = destination;
  25. }
  26. if (step < minStep) minStep = step;
  27. }
  28. Console.WriteLine($"The answer is : {minStep}");
  29. }
  30. }
  31. }