hdu 1700

来源:互联网 发布:华宇软件股票 编辑:程序博客网 时间:2024/06/11 18:54

Points on Cycle

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1853    Accepted Submission(s): 675


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
21.500 2.000563.585 1.251
 

Sample Output
0.982 -2.299 -2.482 0.299-280.709 -488.704 -282.876 487.453



一个以原点为圆心的圆和圆上一点,求圆上另外两点使得三点距离最长。

由数据可知 三点为等边三角形。

所以可得方程组  x^2+y^2=r^ ,   (x-a)^2+(y-b)^2=3r^2

求解可得y坐标


再由向量的夹角公式可求出x坐标


#include <iostream>#include <cstdio>#include <cmath>#define minn 1e-8using namespace std;struct Point{    double x,y;};int main(){    Point P;    int t;    cin>>t;    while(t--)    {        cin>>P.x>>P.y;        double r=P.x*P.x+P.y*P.y;        double A,B,C;        A=r;        B=P.y*r;        C=r*r/4-P.x*P.x*r;        Point a,b;        a.y=(-sqrt(B*B-4*A*C)-B)/(2*A);        b.y=(sqrt(B*B-4*A*C)-B)/(2*A);        //向量夹角公式        if(abs(P.x-0)<minn)        {            a.x=-sqrt(r-a.y*a.y);            b.x=sqrt(r-b.y*b.y);        }        else        {            a.x=(-r/2-a.y*P.y)/P.x;            b.x=(-r/2-b.y*P.y)/P.x;        }        printf("%.3lf %.3lf %.3lf %.3lf\n",a.x,a.y,b.x,b.y);    }}





0 0
原创粉丝点击