Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <ctime>
- #include <random>
- using namespace std;
- ifstream fin("input.txt");
- double sqr(double a) { return a * a; }
- struct Point
- {
- double x;
- double y;
- void readPoint()
- {
- fin >> x >> y;
- }
- void printPoint()
- {
- cout << x << ' ' << y << endl << endl;
- }
- };
- double getRange(Point a, Point b)
- {
- return sqr(a.x - b.x) + sqr(a.y - b.y);
- }
- const int N = 10;//array size;
- int main()
- {
- Point a[N];
- int n; fin >> n;
- for (int i = 0; i < n; ++i)
- a[i].readPoint();
- Point ans;
- double ansRange = -1;
- for (int i = 0; i < n; ++i) {
- double currentRange = 0;
- for (int j = 0; j < n; ++j)
- currentRange += getRange(a[i], a[j]);
- if (currentRange > ansRange)
- {
- ansRange = currentRange;
- ans = a[i];
- }
- }
- cout << "answer: " << ans.x << ' ' << ans.y << endl;
- return 0;
- }
- /*
- example
- 3
- 1 2
- 3 5
- -3 -5
- answer : 1 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement