2013
12-21

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.

There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.

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.

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

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

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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

typedef long long LL;
const int N=21;
const LL II=1000000007;

double x,y,r,r2;
double xx0,yy0,xx1,yy1;

int main()
{
int T;
cin>>T;
while(T--)
{
scanf("%lf%lf",&x,&y);
r2=(x*x+y*y);
double a,b,c;
a=r2;
b=r2*y;
c=r2*r2/4-x*x*r2;
yy0=(-b-sqrt(b*b-4*a*c))/2/a;
yy1=(-b+sqrt(b*b-4*a*c))/2/a;
/*/这个地方求解x不能用x*x+y*y=r2来算，应为不知道正负号
xx0=sqrt(r2-yy0*yy0);
xx1=sqrt(r2-yy1*yy1);*/
if(fabs(x-0)<1e-7)
{
xx0=-sqrt(r2-yy0*yy0);
xx1=sqrt(r2-yy1*yy1);
}
else
{
xx0=(-r2/2-yy0*y)/x;
xx1=(-r2/2-yy1*y)/x;
}
printf("%.3lf %.3lf %.3lf %.3lf\n",xx0,yy0,xx1,yy1);
}

return 0;
}

1. 有两个重复的话结果是正确的，但解法不够严谨，后面重复的覆盖掉前面的，由于题目数据限制也比较严，所以能提交通过。已更新算法