ACM 之 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 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<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
//const double pi=3.1415926;
double a,b,c,d,x,y,x1,x2,r,y11,y2,n;
int main()
{
    cin>>n;
    while(n--)
    {

            cin>>x>>y;
            r=sqrt(pow(x,2)+pow(y,2));
            a=1;
            b=y;
            c=r*r/4-x*x;
            d=b*b-4*a*c;
            d=b*b-4*a*c;
            y11=(-1*b-sqrt(d))/(2*a);
            y2=(-1*b+sqrt(d))/(2*a);
            if(x==0)
            {
                x1=-sqrt(r*r-y11*y11);
                x2=sqrt(r*r-y2*y2);
            }
            else
            {
                x1=(-1*r*r/2-y*y11)/x;
                x2=(-1*r*r/2-y*y2)/x;
            }
            cout<<setprecision(3)<<setiosflags(ios::fixed)<<x1<<" "<<y11<<" "<<x2<<" "<<y2<<endl;
    }
    return 0;
}

意見反饋 || 任何建議

聯系我(新浪)
郵箱:qianlizhihao@gmail.com

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容