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;
}
时间: 2024-08-02 15:10:20

ACM——Points on Cycle的相关文章

hdu 1700 Points on Cycle(坐标旋转)

http://acm.hdu.edu.cn/showproblem.php?pid=1700 Points on Cycle Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1567    Accepted Submission(s): 570 Problem Description There is a cycle with its c

hdu 1700 Points on Cycle(几何)(中等)

Points on Cycle Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1992    Accepted Submission(s): 721 Problem Description There is a cycle with its center on the origin. Now give you a point on t

hdu 1700 Points on Cycle 水几何

已知圆心(0,0)圆周上的一点,求圆周上另外两点使得三点构成等边三角形. 懒得推公式,直接用模板2圆(r1=dist,r2=sqrt(3)*dist)相交水过 #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<iterator> using namespace std; #define eps 1e-6 typedef long lon

暑假集训(2)第八弹 ----- Points on Cycle(hdu1700)

Points on Cycle Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 th

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

Points on Cycle

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 dis

ACM ——Points in Segments

Given n points (1 dimensional) and q segments, you have to find the number of points that lie in each of the segments. A point pi will lie in a segment A B if A ≤ pi ≤ B. For example if the points are 1, 4, 6, 8, 10. And the segment is 0 to 5. Then t

HDU1700 Points on Cycle (最大内接三角形)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1700 题意: 一个圆心为原点的圆,告诉你圆上一点,求圆上另外两点的坐标使圆的面积最大 分析: 三角形的面积由底边和高两个因素决定,不管底边所在弦有多少, 但其高只有经过圆心的为最大, 故毫无质疑必须是等腰三角形. 设等腰三角形ABC,高AH,圆心O,AO=BO=R,OH=AH-AO,设高为x, BH=√[R^2-(x-R)^2]=√(2Rx-x^2), ∴S=x√(2Rx-x^2), dS=√(2

HDU 1700 Points on Cycle (几何 向量旋转)

http://acm.hdu.edu.cn/showproblem.php?pid=1700 题目大意: 二维平面,一个圆的圆心在原点上.给定圆上的一点A,求另外两点B,C,B.C在圆上,并且三角形ABC的周长是最长的. 解题思路: 我记得小学的时候给出个一个定理,在园里面正多边形的的周长是最长的,这个定理我不会证明. 所以这里是三角形,当三角形为正三角形的时候,周长是最长的. 因为圆心在原点,所以我就向量(x,y)绕原点逆时针旋转120度和顺时针旋转120度.给定的点A可以看成(x,y)向量.