您的位置:首页 > 其它

HDU 1700 (几何问题)

2010-04-29 22:11 453 查看

PointsonCycle

TimeLimit:1000/1000MS(Java/Others)MemoryLimit:32768/32768K(Java/Others)
TotalSubmission(s):513AcceptedSubmission(s):195


ProblemDescription
Thereisacyclewithitscenterontheorigin.
Nowgiveyouapointonthecycle,youaretofindouttheothertwopointsonit,tomaximizethesumofthedistancebetweeneachother
youmayassumethattheradiusofthecyclewillnotexceed1000.

Input
ThereareTtestcases,ineachcasethereare2decimalnumberrepresentingthecoordinateofthegivenpoint.

Output
Foreachtestcaseyouaresupposedtooutputthecoordinatesofbothoftheunknowpointsby3decimalplacesofprecision
Alwayoutputtheloweronefirst(withasmallerY-coordinatevalue),iftheyhavethesameYvalueoutputtheonewithasmallerX.

NOTE
whenoutput,iftheabsolutedifferencebetweenthecoordinatevaluesX1andX2issmallerthan0.0005,weassumetheyareequal.

SampleInput

2
1.5002.000
563.5851.251


SampleOutput

0.982-2.299-2.4820.299
-280.709-488.704-282.876487.453


题意:一个以原点为中心的圆,告诉你圆上的一个点,求与另外的两个点组成的三角形的周长最长的两点作标。

根据几何知识,知道圆内等边三角形的周长最长。所以题目转化为求已知一个点的圆内接等边三角形的另两点作标。

思路:设P(x,y),一个方程是pow(x,2)+pow(y,2)=pow(r,2);另一个方程是根据向量知识,向量的夹角公式得到方程。

因为圆心角夹角为120度,已知一个向量(即一个点作标),所以COS(2PI/3)=a*b/|a|*|b|;(a,b为向量);

已知角和a向量,就可求b向量b(x,y).由方程组可求得(x,y);最后得到的是一元二次方程组,可得到两个解,即为两个点的作标。


代码如下:

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

intmain()
{
doublex,y,x1,y1,x2,y2,cosx,a,b,c,r,delta;
intt;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&x,&y);
r=sqrt(x*x+y*y);
a=r*r;
b=r*r*y;
c=r*r*r*r/4-x*x*r*r;
delta=b*b-4*a*c;
y1=(-1*b-sqrt(delta))/(2*a);
y2=(-1*b+sqrt(delta))/(2*a);
if(x==0)
{
x1=-sqrt(r*r-y1*y1);
x2=sqrt(r*r-y2*y2);
}
else
{
x1=(-1*r*r/2-y*y1)/x;
x2=(-1*r*r/2-y*y2)/x;
}
printf("%.3lf%.3lf%.3lf%.3lf/n",x1,y1,x2,y2);
}
return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: