T1
一道计几,还行,第一个就是直接三分支线上的点然后求函数谷值,第二个就是 \(\min\{Dist(x_1, x_3), Dist(x_2, x_3)\}\)。
#include <cmath>
#include <iomanip>
#include <fstream>
#include <ctime>
using namespace std;
const double eps = 1e-8;
ifstream cin("fountain.in");
ofstream cout("fountain.out");
struct Point {
double x, y;
};
double r;
Point x[3];
double Dis(Point x, Point y) {
return sqrt(pow(x.x - y.x, 2) + pow(x.y - y.y, 2));
}
Point to(Point x, Point y, double a) {
double xx, yy;
if (x.x > y.x) {
xx = x.x - (x.x - y.x) * a;
} else {
xx = x.x + (y.x - x.x) * a;
}
if (x.y > y.y) {
yy = x.y - (x.y - y.y) * a;
} else {
yy = x.y + (y.y - x.y) * a;
}
return {xx, yy};
}
double Get() {
double l = eps, r = 1;
while (fabs(l - r) > eps) {
double mid1 = l + (r - l) / 3, mid2 = r - (r - l) / 3;
double ans1 = Dis(to(x[0], x[1], mid1), x[2]), ans2 = Dis(to(x[0], x[1], mid2), x[2]);
if (ans2 > ans1) {
r = mid2;
} else {
l = mid1;
}
}
return l;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
for (cin >> t; t; --t) {
cin >> x[0].x >> x[0].y >> x[1].x >> x[1].y >> x[2].x >> x[2].y >> r;
double res2 = max(Dis(x[0], x[2]), Dis(x[1], x[2])) + r;
double ans = Get();
cout << fixed << setprecision(2) << (Dis(to(x[0], x[1], ans), x[2]) - r) << ' ' << res2 << '\n';
}
cout << clock();
return 0;
}