• 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
     
    AC代码:
    #include <iostream>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int main()
    {
        int n;
       double x,y,x1,y1,x2,y2,r;//夹角公式与圆的公式联立
       double a,b,c;
       scanf("%d",&n);
       while(n--)
       {
           scanf("%lf%lf",&x,&y);
           r=sqrt(x*x+y*y);
           a=1;
           b=y;
           c=r*r/4-x*x;
           y1=(-b-sqrt(b*b-4*a*c))/(2*a);
           y2=(-b+sqrt(b*b-4*a*c))/(2*a);
           if(fabs(x-0)<1e-7)
           {
               x1=-sqrt(r*r-y1*y1);
               x2=sqrt(r*r-y2*y2);
           }
           else
    {
        x1=(-r*r/2-y*y1)/x;
        x2=(-r*r/2-y*y2)/x;
    }
           printf("%.3lf %.3lf %.3lf %.3lf
    ",x1,y1,x2,y2);
       }
        return 0;
    }
    
    分析:这是一个几何体,大致意思就是说圆上有三个点问你当它们分别在哪时,两点间的距离最大,实质就是构成一个等边三角时,距离最大,告诉你一个点的坐标让你求另外两个点的坐标.
    首先可以求出圆的半径,然后用两个公式求解方程组

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

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

      心得:做这个题的时候一开始很顺利,但最后那个判断条件我想了很久也没弄懂,搜了一下知道那是排除除数为0的情况,但后面的else的语句又是怎么来的我又弄不懂了,等我先弄懂了再来改吧。
      
     
     
     
     
  • 相关阅读:
    ThreeJS中的点击与交互——Raycaster的用法
    threejs地球之后:动画的控制
    threejs创建地球
    3d模型一般怎么导入到到Threejs中使用
    用three.js开发三维地图实例
    threejs使用各种坑实验过程
    用threejs实现三维全景图
    用threejs 实现3D物体在浏览器展示
    小议线程之单线程、多线程、线程池
    小谈MVC 模式
  • 原文地址:https://www.cnblogs.com/lbyj/p/5696867.html
Copyright © 2020-2023  润新知