B - Points on Cycle

There is a cycle with its center on the origin.
Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other
you may assume that the radius of the cycle will not exceed 1000.
Input
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
Output
For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X.

NOTE
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
Sample Input
2
1.500 2.000
563.585 1.251
Sample Output
0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453

先给出自己的证明显然这三个点是要构成一个内接三角形的:
可设内接三角形三点连接圆点得到的3个角a,b,c。这里写图片描述
周长C = ans * 2 * r
= 2 * r * (cos(a) + cos(b) + cos(c))
即求MAX(ans)
a + b + c = PI / 2
0 < a,b,c < PI / 2
a = x,b = y,c = PI/2 - x - y,0 < x,y < PI/2
ans =
cos(x) + cos(y) + cos(PI/2 - x - y)
ans =
cos(x)+cos(y)+sin(x+y)
ans =
cos(x)+cos(y)+sin(x)cos(y)+sin(y)cos(x)
ans = f(x,y) =
cos(x)+cos(y)+sin(x)cos(y)+sin(y)cos(x)
求导:
f’(x,y)|x =
-sin(x) + cos(y)cos(x) - sin(y)sin(x) = 0
f’(x,y)|y =
-sin(y) + cos(x)cos(y) - sin(x)sin(y) = 0
->-sin(x) + cos(x+y) = -sin(y) + cos(x+y) = 0
->sin(x) = sin(y) = cos(x + y)
->x = y,1 - 2sin^2(x) = sin(x)
t = sin(x)
->2t^2 + t - 1 = 0
(2t - 1)(t + 1) = 0
t = 1/2
sin(x) = 1/2 -> x = PI/6
x = y = PI / 6
f’(x,y)|xx = -cos(x)-cos(y)sin(x)-sin(y)cos(x)
f’(x,y)|xy = -cos(x)sin(y) - sin(x)cos(y)
f’(x,y)|yy = -cos(y)-cos(x)sin(y)-sin(x)cos(y)
A = -sqrt(3)r,B = -sqrt(3) / 2r,C = -sqrt(3)r
AC - B^2 = 3r^2 - 3/4r^2 > 0,A < 0,取极大值
a = b = c = PI / 6
故该内接三角形应为等边三角形
设三点分别为A,B,C,A已知。
由cos

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <string>
#include <cmath>
using namespace std;
#define INF 0x3f3f3f3f
struct point {
    double x;
    double y;
};
double dis(double a, double b, double c, double d) {
    return sqrt((a - c) * (a - c) + (b - d)*(b - d));
}
int main() {
    int T;
    point a, b, c;
    cin >> T;
    while (T--) {
        cin >> a.x >> a.y;
        double r = sqrt(a.x * a.x + a.y * a.y);
        double s = r * sqrt(3);
        double t = sqrt(3) * a.y;
        b.x = (t - a.x) / 2.0;
        if (fabs(a.y - 0) > 1e-7)
            b.y = (-r * r / 2.0 - a.x * b.x) / a.y;
        else
            b.y = sqrt(r * r - b.x * b.x);
        c.x = (-t - a.x) / 2.0;
        if (fabs(a.y - 0) > 1e-7)
            c.y = (-r * r / 2.0 - a.x * c.x) / a.y;
        else
            c.y = -sqrt(r * r - c.x * c.x);
        if (fabs(c.y - b.y) < 0.0005) {
            if (c.x < b.x) {
                printf("%.3f %.3f %.3f %.3f", c.x, c.y, b.x, b.y);
            }
            else {
                printf("%.3f %.3f %.3f %.3f", b.x, b.y, c.x, c.y);
            }
        }
        else {
            if (c.y < b.y) {
                printf("%.3f %.3f %.3f %.3f", c.x, c.y, b.x, b.y);
            }
            else {
                printf("%.3f %.3f %.3f %.3f", b.x, b.y, c.x, c.y);
            }
        }
        putchar('\n');
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值