Advertisement
myloyo

10.1.16

Dec 17th, 2022 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7. struct point {
  8.     double x, y;
  9. };
  10. ifstream in("input.txt");
  11. ofstream out("output.txt");
  12.  
  13. int main()
  14. {
  15.     int n;
  16.     in >> n;
  17.     point t, a[10];
  18.     for (int i = 0; i < n; i++) {
  19.         in >> a[i].x >> a[i].y;
  20.     }
  21.     double* b = new double[n];
  22.     for (int i = 0; i < n; i++) {
  23.         b[i] = 0;
  24.         for (int j = 0; j < n; j++) {
  25.             b[i] += sqrt(pow((a[i].x - a[j].x), 2) + pow((a[i].y - a[j].y), 2));
  26.         }
  27.     }
  28.     int d = 1;
  29.     double minim = b[0] + 1;
  30.     for (int i = 0; i < n; i++) {
  31.         if (b[i] < minim) {
  32.             minim = b[i];
  33.             d = i + 1;
  34.         }
  35.     }
  36.     out << d;
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement