Problem Description
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
译:
问题描述:
有一个以原点为中心的圆
现在给你一个圆上的点,要求你找到圆上的另外的两个点,保证这三个点彼此之间的距离最大
你可以假设圆的半径不超过1000
输入:
有T个测试数据,每个测试数据要求输入两个十进制数代表给定点的坐标
输出
对于每个测试用例,您应该输出两个未知点的坐标,精确到小数点后3位
总是先输出较低的值(Y坐标值较小),如果它们的Y值与较小X值的值相同的话。
请注意
当输出时,如果X1和X2的绝对值小于0.0005,我们假设它们相等。
样例输入
2
1.500 - 2.000
563.585 - 1.251
样例输出
0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453
思路:圆内接正三角形时,3个点彼此之间距离最大,可以先求角度(利用atan2可以由斜率得到角度),每次旋转120,用极坐标的方式再求直角坐标。
#include<stdio.h>
#include<math.h>
#define PI 3.1415926
int main() {
double x, y, r, a;
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &x, &y);
r = sqrt(x*x + y * y); //求半径
a = atan2(y, x); //求角度
for (int i = 0; i < 2; i++) {
a -= PI * 2 / 3; //旋转120度
printf("%0.3lf %0.3lf", r * cos(a), r * sin(a));
if (i == 0)
printf(" ");
}
printf("
");
}
return 0;
}