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
理解
圆内接正边行周长最大!所以这一题就是解一个圆内接三角形的另两个坐标的题.
代码部分
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
//const double pi=3.1415926;
double a,b,c,d,x,y,x1,x2,r,y11,y2,n;
int main()
{
cin>>n;
while(n--)
{
cin>>x>>y;
r=sqrt(pow(x,2)+pow(y,2));
a=1;
b=y;
c=r*r/4-x*x;
d=b*b-4*a*c;
d=b*b-4*a*c;
y11=(-1*b-sqrt(d))/(2*a);
y2=(-1*b+sqrt(d))/(2*a);
if(x==0)
{
x1=-sqrt(r*r-y11*y11);
x2=sqrt(r*r-y2*y2);
}
else
{
x1=(-1*r*r/2-y*y11)/x;
x2=(-1*r*r/2-y*y2)/x;
}
cout<<setprecision(3)<<setiosflags(ios::fixed)<<x1<<" "<<y11<<" "<<x2<<" "<<y2<<endl;
}
return 0;
}