zoukankan      html  css  js  c++  java
  • L

    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
     
    解题思路:

    给你一个点在半径为r的圆上,该圆圆心在原点上,让你求圆上两个点是这两个点与给出这个点的距离最大

    显然是互为120度的时候最大。

    首先可以求出圆的半径,然后用两个公式求解方程组

    a*b=|a|*|b|*cos(120);

    x*x+y*y=r*r;

    解出方程刚好有两个解,及为所求:

     
    代码如下:
     
    #include<cstdio>
    #include<cmath>
    using namespace std;
      int main()
    {
         double x,y,a,b,x1,y1,x2,y2,r,A,B,C;int n;
           scanf("%d",&n);
          while(n--)
          { scanf("%lf %lf",&x,&y); a=-x;
             b=-y;
             r=x*x+y*y;
             A=r;
             B=-r*b;
             C=r*r/4-a*a*r; y1=(-B-sqrt(B*B-4*A*C))/(2*A);
             y2=(-B+sqrt(B*B-4*A*C))/(2*A);
             if(x==0)
             {
                 x1=-sqrt(r-y1*y1);
                 x2=sqrt(r-y2*y2);
             }
             else
             {
                 x1=(r/2-b*y1)/a;
                 x2=(r/2-b*y2)/a;
             }
             printf("%.3lf %.3lf %.3lf %.3lf ",x1,y1,x2,y2);
            }
         return 0;
    }
  • 相关阅读:
    JS 获取网页内容高度 和 网页可视高度 支持IE6789 Firefox Chrome
    JS 回车快捷键登陆页面 兼容火狐和IE
    如何设置span宽度
    实现三行布局页面自适应不同分辨率下的屏幕高度
    电脑个别网站打不开 POSTMAN可以请求通
    克隆DataTable
    Microsoft Visual SourceSafe 6.0 关联VS
    asp.net 网站设置访问超时时长
    sql server management studio(ssms)连接多个数据库注意事项
    ASP.NET Core 开发中间件(StaticFiles)使用
  • 原文地址:https://www.cnblogs.com/441179572qqcom/p/5693270.html
Copyright © 2011-2022 走看看