L - Points on Cycle

        这个题是给一个点,求以原点为圆心的内接三角形边长最长的。这样一来,肯定是正三角形边长最长。然后看好多人都是直接解交点方程,解向量方程,是不是太麻烦了一点。直接坐标旋转公式(蓝皮书P256)就OK了,后面输出的时候要判断一下哪个先输出。


坐标旋转公式:

x'=xcosa-ysina, y'=xsina+ycosa  (a是旋转角度)


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 <cstdio>
using namespace std;
class Point
{
public:
    double x;
    double y;
    Point(double px, double py):x(px),y(py){}
    void Rotate(double rad);
    void Print();
};
void Point::Rotate(double rad)
{
    ///坐标旋转函数
    double tx,ty;
    tx=x*cos(rad)-y*sin(rad);
    ty=x*sin(rad)+y*cos(rad);
    x=tx;
    y=ty;
}
void Point::Print()
{
    printf("%.3lf %.3lf", x, y);
}
const double PI=3.141592654;
int main()
{
    int n;
    double x,y;
    cin>>n;
    while(n--)
    {
        cin>>x>>y;
        Point point1(x,y);
        Point point2(x,y);
        point1.Rotate(2*PI/3);
        point2.Rotate(-2*PI/3);
        //判断两个点的大小
        int maxPoint=(point1.y<point2.y || point1.y==point2.y && point1.x<point2.x)?1:2;
        if(maxPoint==1)
        {
            point1.Print();
            cout<<" ";
            point2.Print();
            cout<<endl;
        }
        if(maxPoint==2)
        {
            point2.Print();
            cout<<" ";
            point1.Print();
            cout<<endl;
        }
    }
    return 0;
}