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 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
 
 
//题目大意是一个圆内有一点(半径未知),要求过这个点做圆内最大周长的三角形
这道题其实不难,关键是你能不能找到公式... 就是旋转向量法(算法竞赛入门经典训练指南256页),没有书就用普通方法也行:
一个圆的内接三角形周长最长的是正三角形。设给出的为点A(x,y),圆的半径为R,连接AO,反向延长AO与圆交于点O',以O'为圆心,R为半径画圆,两个圆的交点坐标就是所求的答案。
这个方法就看我同学的博客吧!点击查看
下面是我的:
#include <iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>

using namespace std;
const  double PI=acos(-1.0);
struct Point
{
    double x;
    double y;
    Point(double x = 0, double y = 0): x(x), y(y){}
};
typedef Point Vector;
Vector Rotate(Vector A, double rad)//向量旋转公式
{
    return Vector(A.x * cos(rad) - A.y * sin(rad), A.y * cos(rad) + A.x * sin(rad));
}

int main()
{
    Point point[3];
    int n;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lf %lf",&point[0].x,&point[0].y);
        point[1]=Rotate(point[0],PI*2/3);//逆时针旋转120度
        point[2]=Rotate(point[0],-PI*2/3);//顺时针旋转120度
        int maxPoint=(point[1].y<point[2].y || point[1].y==point[2].y && point[1].x<point[2].x)?1:2;//排序
        if(maxPoint==1)
            printf("%.3lf %.3lf %.3lf %.3lf\n",point[1].x,point[1].y,point[2].x,point[2].y);
        if(maxPoint==2)
            printf("%.3lf %.3lf %.3lf %.3lf\n",point[2].x,point[2].y,point[1].x,point[1].y);
    }
    return 0;
}
View Code

 

 

posted @ 2016-07-20 19:21  君子酱  阅读(192)  评论(0编辑  收藏  举报