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
     
    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的语句又是怎么来的我又弄不懂了,等我先弄懂了再来改吧。
      
     
     
     
     
  • 相关阅读:
    php截取字符串
    PHP数据类型转换(字符转数字,数字转字符)
    php数组添加元素的方法
    更改jdk后,eclipse运行jsp出错
    U盘启动装完系统后 一拔下优盘 就不能进入系统
    SVN回滚版本
    在JSP中如何使用JavaBean
    Python使用numpy实现BP神经网络
    神经网络测试结果很差,该怎么做
    神经网络测试结果很差,该怎么做
  • 原文地址:https://www.cnblogs.com/lbyj/p/5696867.html
Copyright © 2011-2022 走看看