diff --git a/.vs/comivoyar/v15/.suo b/.vs/comivoyar/v15/.suo index 98b5f1c..ab957f6 100644 Binary files a/.vs/comivoyar/v15/.suo and b/.vs/comivoyar/v15/.suo differ diff --git a/.vs/comivoyar/v15/Server/sqlite3/storage.ide-shm b/.vs/comivoyar/v15/Server/sqlite3/storage.ide-shm index 2ba1f10..21baf06 100644 Binary files a/.vs/comivoyar/v15/Server/sqlite3/storage.ide-shm and b/.vs/comivoyar/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/comivoyar/v15/Server/sqlite3/storage.ide-wal b/.vs/comivoyar/v15/Server/sqlite3/storage.ide-wal index c3199ab..8086c79 100644 Binary files a/.vs/comivoyar/v15/Server/sqlite3/storage.ide-wal and b/.vs/comivoyar/v15/Server/sqlite3/storage.ide-wal differ diff --git a/comivoyar/Program.cs b/comivoyar/Program.cs index 77f78b4..b8a0eed 100644 --- a/comivoyar/Program.cs +++ b/comivoyar/Program.cs @@ -20,31 +20,23 @@ namespace komvo { string[] str = line.Split(); Points.Add(new Point { X = int.Parse(str[0]), Y = int.Parse(str[1]) }); + WriteLine(str[0] + " " + str[1]); } } + WriteLine(); int matr = Points.Count; double[,] Matrix = new double[matr, matr]; - - foreach (Point p in Points) - { - WriteLine("{0} {1}", p.X, p.Y); - } - WriteLine(); - - for (int i = 0; i < Points.Count; i++) { for (int j = i; j < Points.Count - 1; j++) { - Matrix[i, j + 1] = Math.Sqrt(Math.Pow(Points[j + 1].X - Points[i].X, 2) + Math.Pow(Points[j + 1].Y - Points[i].Y, 2)); - Write("{0} {1} : {2:N2}\t", Points[i].X, Points[j + 1].X, Matrix[i, j]); + Matrix[i, j + 1] = Matrix[j + 1, i] = + Math.Sqrt(Math.Pow(Points[j + 1].X - Points[i].X, 2) + Math.Pow(Points[j + 1].Y - Points[i].Y, 2)); } - WriteLine(); } - for (int i = 0; i < matr; i++) { for (int j = 0; j < matr; j++) Write("{0:00.00} ", Matrix[i, j]); @@ -54,16 +46,14 @@ namespace komvo string formP = string.Empty; for (int i = 2; i <= Points.Count; i++) formP += i.ToString(); - WriteLine("{0} {1}", formP, Fact(Points.Count - 1)); + int fct = Fact(Points.Count - 1); + WriteLine("{0} {1}", formP, fct); WriteLine("\n\n"); - int[] routes = new int[Fact(Points.Count - 1)]; - double[] leng = new double[Fact(Points.Count - 1)]; + int[] routes = new int[fct]; + double[] leng = new double[fct]; - int waves = 0; - if (Points.Count == 4) waves = 1; - else if (Points.Count == 5) waves = 4; - else if (Points.Count == 6) waves = 20; + int waves = fct / 6; int cn = 1, cn2 = 0; string inf = formP; @@ -125,42 +115,9 @@ namespace komvo //} //cn++; } - - - - - //routes[0] = int.Parse(formP); - //routes[1] = int.Parse(Swap(formP, 1, 2)); - //routes[2] = int.Parse(formP = Swap(formP, 0, 1)); - //routes[3] = int.Parse(Swap(formP, 1, 2)); - //routes[4] = int.Parse(formP = Swap(formP, 0, 2)); - //routes[5] = int.Parse(Swap(formP, 1, 2)); - } - - - - - for (int i = 0; i < routes.Length; i++) - { - double res = 0; - char[] ch = routes[i].ToString().ToCharArray(); - for(int j = 0; j < ch.Length; j++) - { - if (j == 0) res += Matrix[0, 1]; - else if (j == ch.Length - 1) - { - res += Matrix[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; - res += Matrix[0, int.Parse(ch[j].ToString()) - 1]; - } - else - { - res += Matrix[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; - } - } - leng[i] = res; - } + CountLen(ref leng, Matrix, routes); double optim = leng[0]; int oIndex = 0; @@ -181,7 +138,7 @@ namespace komvo if (routes[i].Equals(routes[j])) WriteLine("{0} {2}:: {1} {3}!!!!", routes[i], routes[j], i, j); } WriteLine("\n\n1{1}1 - оптимальный маршрут длинной {0:00.00}\nВсего маршрутов {2}\n{4} {3}", - optim, routes[oIndex], routes.Length, Fact(Points.Count - 1), Points.Count); + optim, routes[oIndex], routes.Length, fct, Points.Count); @@ -217,6 +174,29 @@ namespace komvo } + public static void CountLen (ref double[] result, double[,] mtr, int[] rts) + { + for (int i = 0; i < rts.Length; i++) + { + double res = 0; + char[] ch = rts[i].ToString().ToCharArray(); + for (int j = 0; j < ch.Length; j++) + { + if (j == 0) res += mtr[0, int.Parse(ch[j].ToString()) - 1]; + else if (j == ch.Length - 1) + { + res += mtr[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; + res += mtr[0, int.Parse(ch[j].ToString()) - 1]; + } + else + { + res += mtr[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; + } + } + result[i] = res; + } + } + public partial struct Point { public int X { get; set; } diff --git a/comivoyar/bin/Debug/comivoyar.exe b/comivoyar/bin/Debug/comivoyar.exe index eb2a5cd..53c9b7e 100644 Binary files a/comivoyar/bin/Debug/comivoyar.exe and b/comivoyar/bin/Debug/comivoyar.exe differ diff --git a/comivoyar/bin/Debug/comivoyar.pdb b/comivoyar/bin/Debug/comivoyar.pdb index d77edf6..d2ad6e0 100644 Binary files a/comivoyar/bin/Debug/comivoyar.pdb and b/comivoyar/bin/Debug/comivoyar.pdb differ diff --git a/comivoyar/bin/Debug/coord.txt b/comivoyar/bin/Debug/coord.txt index d140c96..1750aa9 100644 --- a/comivoyar/bin/Debug/coord.txt +++ b/comivoyar/bin/Debug/coord.txt @@ -1,5 +1,4 @@ 0 0 +0 20 20 20 -30 30 -40 40 -50 50 \ No newline at end of file +20 0 \ No newline at end of file diff --git a/comivoyar/obj/Debug/comivoyar.csproj.CoreCompileInputs.cache b/comivoyar/obj/Debug/comivoyar.csproj.CoreCompileInputs.cache index 125c6b5..e4c5453 100644 --- a/comivoyar/obj/Debug/comivoyar.csproj.CoreCompileInputs.cache +++ b/comivoyar/obj/Debug/comivoyar.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -a325577e7d0bb098d5c8871f5acaa6c0c34b21c6 +6eed873852f8ce9c50ebe974dac1f20cc4ef270e diff --git a/comivoyar/obj/Debug/comivoyar.exe b/comivoyar/obj/Debug/comivoyar.exe index eb2a5cd..53c9b7e 100644 Binary files a/comivoyar/obj/Debug/comivoyar.exe and b/comivoyar/obj/Debug/comivoyar.exe differ diff --git a/comivoyar/obj/Debug/comivoyar.pdb b/comivoyar/obj/Debug/comivoyar.pdb index d77edf6..d2ad6e0 100644 Binary files a/comivoyar/obj/Debug/comivoyar.pdb and b/comivoyar/obj/Debug/comivoyar.pdb differ