Problem Link Fifa and Fafa codeforces 935-C
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct point {
ll x, y;
point(ll a = 0, ll b = 0) : x(a), y(b) {}
friend istream &operator>>(istream &in, point &p) {
in >> p.x >> p.y;
return in;
}
friend double operator-(const point &a, const point &b) {
ll dx = a.x - b.x;
ll dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
}
};
void solve() {
double R;
cin >> R;
point p1, p2;
cin >> p1 >> p2;
double dist = p2 - p1;
if (dist >= R) {
cout << p1.x << ' ' << p1.y << ' ' << R;
}
else if (dist == 0) {
cout << p1.x + R / 2 << ' ' << p1.y << ' ' << R / 2;
}
else {
double something = ( R - dist) / 2, somex = (p1.x - p2.x) / dist, somey = (p1.y - p2.y) / dist;
cout << p1.x + somex * something << ' ' << p1.y + somey * something << ' ' << ( R + dist) / 2;
}
}
int main() {
ll t = 1;
// cin >> t;
cout << fixed << setprecision(7);
while (t --)
solve();
}
the first two conditions make complete sense but the problem is in the last condition
I know how r is found but super confused about x_ap and y_ap can someone explain mathematically and intuitively.