Advertisement
Infiniti_Inter

66 1 (14)

May 23rd, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <ctime>
  5. #include <random>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. ifstream fin("input.txt");
  11.  
  12. double sqr(double a) { return a * a; }
  13.  
  14.  
  15. struct Point
  16. {
  17.     double x;
  18.     double y;
  19.     void readPoint()
  20.     {
  21.         fin >> x >> y;
  22.     }
  23.     void printPoint()
  24.     {
  25.         cout << x << ' ' << y << endl << endl;
  26.     }
  27. };
  28.  
  29. double getRange(Point a, Point b)
  30. {
  31.     return sqr(a.x - b.x) + sqr(a.y - b.y);
  32. }
  33.  
  34. const int N = 10;//array size;
  35. int main()
  36. {
  37.     Point a[N];
  38.     int n; fin >> n;
  39.     for (int i = 0; i < n; ++i)
  40.         a[i].readPoint();
  41.     Point ans;
  42.     double ansRange = -1;
  43.     for (int i = 0; i < n; ++i) {
  44.         double currentRange = 0;
  45.         for (int j = 0; j < n; ++j)
  46.             currentRange += getRange(a[i], a[j]);
  47.         if (currentRange > ansRange)
  48.         {
  49.             ansRange = currentRange;
  50.             ans = a[i];
  51.         }
  52.     }
  53.     cout << "answer: " << ans.x << ' ' << ans.y << endl;
  54.     return 0;
  55. }
  56. /*
  57. example
  58. 3
  59.  
  60. 1 2
  61. 3 5
  62. -3 -5
  63.  
  64.  
  65. answer : 1 2
  66. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement