Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
Output
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.
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
1.500 2.000
563.585 1.251
Sample Output
-280.709 -488.704 -282.876 487.453
问题分析:它是一道几何题,假设以知点a坐标为(x0,y0),位置点b,c为(x1,y1),(x2,y2). 圆方程为x2+y2 = r2;可将圆方程化为x=rcosα,y=rsinα;
又有x12+y1 2= r2 = x02+y0 2,(a*b)/|a|*|b| = cos120。
易得 acosα + bsinα = -0.5r
(acosα)2 = (0.5r + bsinα)2
r2sinα2 + rbsinα + 0.25r2 - a2 = 0
得 x1 = -0.5*b + a*√3 * 0.5 或 x1 = -0.5*b - a*√3 *0.5(舍去)
及 y = -0.5*b - a*√3 * 0.5 或 y= 0.5*b + a*√3 * 0.5(舍去)
同理可得x2,y2;
也可直接利用cos(α+β) = cosαcosβ - sinαsinβ ,sin(α+β) = sinαcosβ + cosαsinβ求解,
#include <cstdio>
#include <cmath>
int main()
{
double a,b,x0,y0,x1,y1,x2,y2;
int t;
a=sqrt(3.0)/;
b=-0.5;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&x0,&y0);
x1 = b*x0 - a*y0;
y1 = b*y0 + a*x0;
x2 = b*x0 + a*y0;
y2 = b*y0 - a*x0;
if(y1<y2 || ((fabs(y1-y2) < 0.005) && x1 < x2))
printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
else
printf("%.3lf %.3lf %.3lf %.3lf\n",x2,y2,x1,y1);
}
return ;
}