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;
}
T2
每次操作後將數列離散化並記錄對應區間,然後對數列進行 \(\gcd\), 如果 \(a\) 是 \(gcd\) 的因數,就不用操作。