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;
    }
  • 相关阅读:
    IIS7.5 HTTP 错误 500 调用loadlibraryex失败的解决方法
    VB6.0 excel 导入和导出
    SQL 实现 成绩表形式的转换
    计算月初和月末,年初和年末的日期
    一篇文章学LINQ(原创)
    浙江省仙居县发现罕见丹霞地貌大型“天坑”
    浙江省仙居县发现特大型丹霞地貌洞穴
    EFUpdate
    163邮件出错:不允许使用邮箱名称。 服务器响应为: authentication is required,smtp7,C8CowEDpS0+Uke9VvSmXBg--.546S2 1441763733
    vmware 安装dos注意
  • 原文地址:https://www.cnblogs.com/441179572qqcom/p/5693270.html
Copyright © 2011-2022 走看看