设为首页 加入收藏

TOP

hdu1700 Points on Cycle (数学)
2014-11-23 17:44:35 来源: 作者: 【 】 浏览:6
Tags:hdu1700 Points Cycle 数学

Problem 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   #include   int main()  {      int t;      double x[3],y[3],c[2],a,b;      scanf("%d",&t);      while(t--)      {          scanf("%lf%lf",&x[0],&y[0]);          c[0]=x[0]*x[0]+y[0]*y[0];          if(x[0]==0)          {              y[1]=y[2]=-y[0]/2;              x[1]=-sqrt(c[0]-y[1]*y[1]);              x[2]=sqrt(c[0]-y[2]*y[2]);          }          else          {              c[1]=-c[0]+c[0]*c[0]/(4*x[0]*x[0]);              b=c[0]*y[0]/(x[0]*x[0]);              a=1+y[0]*y[0]/(x[0]*x[0]);              y[1]=(-b-sqrt(b*b-4*a*c[1]))/(2*a);              y[2]=(-b+sqrt(b*b-4*a*c[1]))/(2*a);              x[1]=-c[0]/(2*x[0])-y[0]*y[1]/x[0];              x[2]=-c[0]/(2*x[0])-y[0]*y[2]/x[0];          }          printf("%.3lf %.3lf %.3lf %.3lf\n",x[1],y[1],x[2],y[2]);      }  }  #include
#include
int main()
{
    int t;
    double x[3],y[3],c[2],a,b;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf%lf",&x[0],&y[0]);
        c[0]=x[0]*x[0]+y[0]*y[0];
        if(x[0]==0)
        {
            y[1]=y[2]=-y[0]/2;
            x[1]=-sqrt(c[0]-y[1]*y[1]);
            x[2]=sqrt(c[0]-y[2]*y[2]);
        }
        else
        {
            c[1]=-c[0]+c[0]*c[0]/(4*x[0]*x[0]);
            b=c[0]*y[0]/(x[0]*x[0]);
            a=1+y[0]*y[0]/(x[0]*x[0]);
            y[1]=(-b-sqrt(b*b-4*a*c[1]))/(2*a);
            y[2]=(-b+sqrt(b*b-4*a*c[1]))/(2*a);
            x[1]=-c[0]/(2*x[0])-y[0]*y[1]/x[0];
            x[2]=-c[0]/(2*x[0])-y[0]*y[2]/x[0];
        }
        printf("%.3lf %.3lf %.3lf %.3lf\n",x[1],y[1],x[2],y[2]);
    }
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA424 - Integer Inquiry 下一篇HDU 4554 叛逆的小明

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·请问c语言刚入门,该 (2025-12-26 10:21:04)
·python 编程怎么定义 (2025-12-26 10:21:01)
·09-指 针 (一)-c语言 (2025-12-26 10:20:58)
·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)