zoukankan      html  css  js  c++  java
  • ACM——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
     
     
    解释:这题主要用到了数学的向量夹角公式,所以这题告诉了我们数学好就是王道。。。
     
    #include<cmath>
    #include<cstdio>
    #include<algorithm>//交换函数
    
    using namespace std;
    
    const double PI = acos(-1.0);//就是pi的值
    
    struct Point
    {
        double x, y;
    
        Point(double x = 0, double y = 0): x(x), y(y){}
    
        void scan()
        {
            scanf("%lf%lf", &x, &y);
        }
    
        void print()
        {
            printf("%.3lf %.3lf", x, y);
        }
    
    };
    
    
    
    Point rotate(Point A, double rad)
    {
        return Point(A.x * cos(rad) - A.y * sin(rad), A.y * cos(rad) + A.x * sin(rad));//旋转向量公式
    }
    
    int main()
    {
        int i;
        Point p[3];
        scanf("%d", &i);
        while(i--)
        {
            p[0].scan();
            p[1] = rotate(p[0], PI * 2 / 3);//逆时针旋转120度
            p[2] = rotate(p[0], -PI * 2 / 3);//顺时针旋转120度
    
            if(p[2].y < p[1].y||(p[2].y == p[1].y && p[2].x < p[1].x))
                swap(p[1], p[2]);//交换
    
            p[1].print(); //
            printf(" ");
    
            p[2].print(); //
            printf("\n");
        }
        return 0;
    }
  • 相关阅读:
    2019-07-08 L410 EST科技英语翻译
    L405 NYC-ATF4
    L403 Royal espionage
    L402 EST
    L401 哭声识别
    L400 How Trees Affect the Weather
    L398
    final, finally, finalize 的区别
    try {}里有一个 return 语句, 那么紧跟在这个 try 后的 finally {}里的 code会不会被执行,什么时候被执行,在 return 前还是后?
    下 面 这 条 语 句 一 共 创 建 了 多 少 个 对 象 : String s="a"+"b"+"c"+"d";
  • 原文地址:https://www.cnblogs.com/shadervio/p/5696971.html
Copyright © 2011-2022 走看看