You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.4 KiB
158 lines
4.4 KiB
6 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.IO;
|
||
|
using static System.Console;
|
||
|
|
||
|
namespace komvo
|
||
|
{
|
||
|
class Program
|
||
|
{
|
||
|
public static List<point> Points = new List<point>();
|
||
|
|
||
|
static void Main(string[] args)
|
||
|
{
|
||
|
string file = "coord.txt";
|
||
|
|
||
|
using (StreamReader cr = new StreamReader(file))
|
||
|
{
|
||
|
string line;
|
||
|
while ((line = cr.ReadLine()) != null)
|
||
|
{
|
||
|
string[] str = line.Split();
|
||
|
Points.Add(new point { X = int.Parse(str[0]), Y = int.Parse(str[1]) });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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]);
|
||
|
}
|
||
|
WriteLine();
|
||
|
}
|
||
|
|
||
|
|
||
|
for (int i = 0; i < 4; i++)
|
||
|
{
|
||
|
for (int j = 0; j < 4; j++) Write("{0:00.00} ", Matrix[i, j]);
|
||
|
WriteLine();
|
||
|
}
|
||
|
|
||
|
string formP = string.Empty, formN = string.Empty;
|
||
|
for (int i = 2; i <= Points.Count; i++) formP += i.ToString();
|
||
|
for (int i = Points.Count; i >= 2; i--) formN += i.ToString();
|
||
|
WriteLine("{0} {1} {2}", formP, formN, Fact(Points.Count - 1));
|
||
|
|
||
|
WriteLine(formP + " " + Swap(formP, 1, 2));
|
||
|
WriteLine("\n\n");
|
||
|
|
||
|
int[] routes = new int[Fact(Points.Count - 1)];
|
||
|
double[] leng = new double[Fact(Points.Count - 1)];
|
||
|
|
||
|
int begin = int.Parse(formP), end = int.Parse(formN);
|
||
|
for (int b = begin; b <= 234; b++)
|
||
|
{
|
||
|
string number = b.ToString();
|
||
|
routes[0] = int.Parse(number);
|
||
|
routes[1] = int.Parse(Swap(number, 1, 2));
|
||
|
routes[2] = int.Parse(number = Swap(number, 0, 1));
|
||
|
routes[3] = int.Parse(Swap(number, 1, 2));
|
||
|
routes[4] = int.Parse(number = Swap(number, 0, 2));
|
||
|
routes[5] = int.Parse(Swap(number, 1, 2));
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//for (int i = 0; i < Points.Count; i++)
|
||
|
//{
|
||
|
// for (int j = i; j < Points.Count - 1; j++)
|
||
|
// {
|
||
|
|
||
|
// }
|
||
|
// //WriteLine();
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < leng.Length; i++) WriteLine("{0:N2}", leng[i]);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//WriteLine(routes[0]);
|
||
|
//MessageBox.Show(Math.Sqrt(-1).ToString());
|
||
|
ReadKey();
|
||
|
|
||
|
}
|
||
|
|
||
|
public static string Swap(string value, int first, int second)
|
||
|
{
|
||
|
char[] res = value.ToCharArray();
|
||
|
res[first] = value[second];
|
||
|
res[second] = value[first];
|
||
|
value = new string(res);
|
||
|
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
|
||
|
static public int Fact(int nm)
|
||
|
{
|
||
|
int res = 1;
|
||
|
for (int i = 1; i <= nm; i++)
|
||
|
{
|
||
|
res *= i;
|
||
|
}
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
|
||
|
public partial struct point
|
||
|
{
|
||
|
public int X { get; set; }
|
||
|
public int Y { get; set; }
|
||
|
}
|
||
|
}
|
||
|
}
|