Click Here to go back to the homepage.

Completing the Square Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    //double the distance to center from opposite corner
    int x1, x2, x3, y1, y2, y3;

    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double d1 = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    double d2 = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
    pair<int, int> start;
    int other[4];
    if(d1 > d2){
        start = {x3, y3};
        other[0] = x1;
        other[1] = y1;
        other[2] = x2;
        other[3] = y2;
    } else if(d2 > d1) {
        start = {x1, y1};
        other[0] = x3;
        other[1] = y3;
        other[2] = x2;
        other[3] = y2;
    } else {
        start = {x2, y2};
        other[0] = x3;
        other[1] = y3;
        other[2] = x1;
        other[3] = y1;
    }
    double num1 = ((other[0] + other[2]) / 2.0);
    double num2 = ((other[1] + other[3]) / 2.0);
    double x = 2 * abs(start.first - num1);
    double y = 2 * abs(start.second - num2);
    start.first += num1 >= start.first ? x : -x;
    start.second += num2 >= start.second ? y : -y;
    cout << start.first << " " << start.second << endl;
    return 0;   
}