HDU-1700 Points on Cycle

来源:互联网 发布:mac 相对于卷宗的格式 编辑:程序博客网 时间:2024/06/05 06:08

Problem 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
题解:用向量旋转公式:x1=x*cos(A)-y*sin(A),y1=x*sin(A)+y*cos(A). (x,y)为已知向量,A为旋转角度。

#include<iostream>#include<cmath>using namespace std;#define PI acos(-1.0)struct Point {    double x, y;};Point Rotate(Point A, double angle){    Point B;    B.x = A.x*cos(angle) - A.y*sin(angle);    B.y = A.x*sin(angle) + A.y*cos(angle);    return B;}void sswap(Point &m, Point &n){    Point w;    if (m.y < n.y)return;    else if (m.y > n.y)    {        w = m;m = n;n = w;    }    else    {        if (m.x <= n.x)return;        else        {            w = m; m = n; n = w;        }    }}int main(){    int T;    cin >> T;    while (T--)    {        Point A, B, C;        cin >> A.x >> A.y;        B = Rotate(A, PI * 2 / 3);        C = Rotate(A, -PI * 2 / 3);        sswap(B, C);        printf("%.3lf %.3lf %.3lf %.3lf\n", B.x, B.y, C.x, C.y);    }    return 0;}
0 0
原创粉丝点击