您的位置:首页 > 其它

HDU1700Points on Cycle(圆心半径)

2015-08-22 17:40 323 查看

Points on Cycle

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1897 Accepted Submission(s): 688


[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

2 1.500 2.000 563.585 1.251

[align=left]Sample Output[/align]

0.982 -2.299 -2.482 0.299 -280.709 -488.704 -282.876 487.453

[align=left]Source[/align]
2007省赛集训队练习赛(1)

[align=left]Recommend[/align]
lcy
思路:已知点(x,y),设所求点为(ax,ay),(bx,by),半径r
满足(1) x^2+y^2=r^2;(2)(x-ax)^2+(y-ay)^2=3 r^2
l联立两式得
(3) -2 ax x^2=r^2+2 ay y
将(1)式带入(3)中得
4 ay^2+4 y ay+r^2-4 x^2 =0
解得ay有两个值即为ay,by

ay = (((-4*y)-sqrt(4*y*4*y-16*(r-4*x*x)))/8);
by = (((-4*y)+sqrt(4*y*4*y-16*(r-4*x*x)))/8);

#include <stdio.h>
#include <math.h>

int main()
{
int t;
double x,y,x2,y2,r;
double ax,ay,bx,by;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&x,&y);
r = x*x+y*y;
ay = (((-4*y)-sqrt(4*y*4*y-16*(r-4*x*x)))/8);
by = (((-4*y)+sqrt(4*y*4*y-16*(r-4*x*x)))/8);
if(x==0)
{
ax=-sqrt(r-ay*ay);    //一定为负数,只有在x=0的时候可这样计算
bx=sqrt(r-by*by);
}
else
{
ax=(-r/2-ay*y)/x;   有(3)式得
bx=(-r/2-by*y)/x;
}
printf("%.3lf %.3lf %.3lf %.3lf\n",ax,ay,bx,by);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: