Guest User

Untitled

a guest
Apr 13th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Deykstr
  7. {
  8.     public class Program
  9.     {
  10.         const int n = 5;
  11.         const int P = 99999;
  12.         static bool[] masCheck = new bool[6];
  13.         static int[] masEnd = { P, P, P, P, P, P  };
  14.         static int[,] masLenght = {
  15.                                   { 0, 7, 9, P, P, 14 },
  16.                                   { 7, 0, 10, 15, P, P },
  17.                                   { 9, 10, 0, 11, P, 2 },
  18.                                   { P, 15, 11, 0, 6, P },
  19.                                   { P, P, P, 6, 0, 9},
  20.                                   { 14, P, 2, P, 9, 0}
  21.                                   };
  22.         static void Main()
  23.         {
  24.             Console.WriteLine("введите начальную точку");
  25.             int nach = Int32.Parse(Console.ReadLine())-1;
  26.             Console.WriteLine("введите конечную точку");
  27.             int conech = Int32.Parse(Console.ReadLine())-1;
  28.            
  29.             int w;
  30.             for (int ii = 0; ii <= n; ii++)
  31.                 masCheck[ii] = false;
  32.             masEnd[nach] = 0;
  33.            
  34.             for (int i = 1; i <= n; i++)
  35.             {
  36.                 w = Find_Min();
  37.  
  38.                 for (int j = 1; j <= n; j++)
  39.                 {
  40.                     if (masCheck[j] == false)
  41.                         Relax(w, j);
  42.                 }
  43.  
  44.                 masCheck[w] = true;
  45.  
  46.             }
  47.  
  48.                 Console.WriteLine(masEnd[conech]);
  49.                 Console.WriteLine(masstr[conech]);
  50.  
  51.         }
  52.  
  53.         public static void Relax(int i, int j)
  54.         {
  55.             if (masEnd[j] > masEnd[i] + masLenght[i, j])
  56.             {
  57.                 masEnd[j] = masEnd[i] + masLenght[i, j];
  58.             }
  59.         }
  60.         public static int Find_Min()
  61.         {
  62.             int w = 0, min = P / 2;
  63.             for (int i = 1; i <= n; i++)
  64.             {
  65.                 if ((masCheck[i] == false) && masEnd[i] < min)
  66.                 {
  67.                     min = masEnd[i];
  68.                     w = i;
  69.                 }
  70.  
  71.             }
  72.             return w;
  73.  
  74.         }
  75.  
  76.     }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment