L - Points on Cycle

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
 
解题思路:

给你一个点在半径为r的圆上,该圆圆心在原点上,让你求圆上两个点是这两个点与给出这个点的距离最大

显然是互为120度的时候最大。

首先可以求出圆的半径,然后用两个公式求解方程组

a*b=|a|*|b|*cos(120);

x*x+y*y=r*r;

解出方程刚好有两个解,及为所求:

 
代码如下:
 
#include<cstdio>
#include<cmath>
using namespace std;
  int main()
{
     double x,y,a,b,x1,y1,x2,y2,r,A,B,C;int n;
       scanf("%d",&n);
      while(n--)
      { scanf("%lf %lf",&x,&y); a=-x;
         b=-y;
         r=x*x+y*y;
         A=r;
         B=-r*b;
         C=r*r/4-a*a*r; y1=(-B-sqrt(B*B-4*A*C))/(2*A);
         y2=(-B+sqrt(B*B-4*A*C))/(2*A);
         if(x==0)
         {
             x1=-sqrt(r-y1*y1);
             x2=sqrt(r-y2*y2);
         }
         else
         {
             x1=(r/2-b*y1)/a;
             x2=(r/2-b*y2)/a;
         }
         printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
        }
     return 0;
}
posted @ 2016-07-21 21:41  头像好帅  阅读(120)  评论(0编辑  收藏  举报