题目:传送门
题意:在一个以原点为圆心的圆中,给你圆上的一个点,让你再选两个点, 使得这三个点构成的内接正三角形周长最大。
思路:
圆周长最大的内接三角形是正三角形:证明
面积最大的内接三角形也是正三角形:链接
那只要将点逆时针旋转 120度 和 顺时针旋转 120 度 得到的两个点就是答案了
#include <bits/stdc++.h> #define LL long long #define mem(i, j) memset(i, j, sizeof(i)) #define rep(i, j, k) for(int i = j; i <= k; i++) #define dep(i, j, k) for(int i = k; i >= j; i--) #define pb push_back #define make make_pair #define INF INT_MAX #define inf LLONG_MAX #define PI acos(-1) #define fir first #define sec second using namespace std; const int N = 15000; const double eps = 1e-8; const double maxL = 10.0; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) { } }; int dcmp(double x) { if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; } Point operator + (Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } Point operator - (Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } Point operator * (Point A, double p) { return Point(A.x * p, A.y * p); } Point operator / (Point A, double p) { return Point(A.x / p, A.y / p); } double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double Length(Point A) { return sqrt(Dot(A, A)); } Point Rotate(Point A, double rad) { /// 向量逆时针旋转 rad (弧度) return Point(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad)); } Point P, ans1, ans2; const double Angle = 2.0 * PI / 3.0; void solve() { scanf("%lf %lf", &P.x, &P.y); ans1 = Rotate(P, Angle); ans2 = Rotate(P, -Angle); if(ans1.y > ans2.y) swap(ans1, ans2); if(ans1.y == ans2.y && ans1.x > ans2.x) swap(ans1, ans2); printf("%.3f %.3f %.3f %.3f ", ans1.x, ans1.y, ans2.x, ans2.y); return ; } int main() { int _; scanf("%d", &_); while(_--) solve(); return 0; }