Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Globalization;
- using System.Security.Cryptography;
- namespace myloyorrr
- {
- class Program
- {
- struct SPoint : IComparable<SPoint>
- {
- public int x, y;
- public SPoint(int x, int y)
- {
- this.x = x; this.y = y;
- }
- public double Distance()
- {
- return Math.Sqrt(x * x + y * y);
- }
- public double DistanceTo(SPoint obj)
- {
- return Math.Sqrt((obj.x - x) * (obj.x - x) + (obj.y - y) * (obj.y - y));
- }
- public int CompareTo(SPoint obj) //проводим переопределением метода
- {
- // CompareTo(T) так, чтобы сравнение элементов
- if (this.Distance() == obj.Distance()) // типа SPoint проводилось по возрастанию
- { //расстоянию от точки до начала координат
- return 0;
- }
- else
- {
- if (this.Distance() > obj.Distance())
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
- }
- }
- static SPoint[] Input(int n, StreamReader sr) //читаем данные из файла
- {
- SPoint[] ar = new SPoint[n];
- for (int i = 0; i < n; i++)
- {
- string[] text = sr.ReadLine().Split(' ');
- ar[i] = new SPoint(int.Parse(text[0]), int.Parse(text[1]));
- }
- return ar;
- }
- static void Print(SPoint[] array, StreamWriter sw) //выводим данные на экран
- {
- foreach (SPoint item in array)
- {
- {
- sw.WriteLine("({0}, {1})", item.x, item.y);
- }
- }
- }
- static void Main()
- {
- using (StreamReader sr = new StreamReader("C:/Настя/in.txt"))
- {
- using (StreamWriter sw = new StreamWriter("C:/Настя/out.txt"))
- {
- int n = int.Parse(sr.ReadLine());
- SPoint[] array = Input(n, sr);
- double[] dist = new double[n];
- double mr = 100000000;
- for (int i = 0; i < n; i++)
- {
- double sum = 0;
- for (int j = 0; j < n; j++)
- {
- if (j != i)
- {
- sum += array[i].DistanceTo(array[j]);
- }
- }
- dist[i] = sum;
- mr = Math.Min(mr, dist[i]);
- sum = 0;
- }
- for (int i = 0; i < n; i++)
- {
- sw.WriteLine(dist[i]);
- }
- for (int i = 0; i < n; i++)
- {
- if (dist[i] == mr)
- {
- sw.WriteLine("({0}, {1})", array[i].x, array[i].y);
- }
- }
- }
- }
- }
- }
- }
- 6
- 1 2
- 15 10
- 25 26
- 3 8
- 4 4
- 6 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement