题目描述
BIGZHUGOD and his three friends are playing a game in a triangle ground.
The number of BIGZHUGOD is 0, and his three friends are numbered from 1 to 3. Before the game begins, three friends stand on three vertices of triangle in numerical order (1 on A, 2 on B, 3 on C), BIGZHUGOD stands inside of triangle.
Then the game begins, three friends run to the next vertex in uniform speed and in straight direction (1 to B, 2 to C, 3 to A and there speeds may different). And BIGZHUGOD can stand in any position inside the triangle.
When any of his friends arrives at next vertex, the game ends.
BIGZHUGOD and his friends have made an agreement: we assume that the beginning is time 0, if during the game, you can find a moment that BIGZHUGOD can block the sight line of 1 to C, 2 to A, 3 to B. Then each friend has to treat BIGZHUGOD with a big meal.
Now BIGZHUGOD knows the lengths of time that his three friends need run to next vertices t1, t2 and t3. He wants to know whether he has a chance to gain three big meals, of course he wants to know in which exciting moment t, he can block three friends\' sight line.
输入
The first line contains an integer T, indicating the number of test cases (T ≤ 1000).
For each case there are three integer t1, t2, t3 (1 ≤ t1, t2, t3 ≤ 100).
输出
If BIGZHUGOD has a chance to gain big meal from his friends, output "YES" and the exciting moment t rounding to 4 digits after decimal point. Otherwise, output "NO".
示例输入
2
1 1 1
3 4 6
示例输出
YES 0.5000
YES 2.0000
题意:BIGZHUGOD和3个人玩游戏,他站在三角形里边,3个人分别站在三角形的三个顶点,并依此朝下一个点走,他知道3个人走到下个点分别所用的时间t1,t2,t3,问是否有一个时刻,使得BIGZHUGOD挡住3个人和每个人相对点的视线,用下面的图来说,就是3个人到达E、F、D时,BIGZHUGOD赢。。
思路:
首先介绍一下赛瓦定理,
塞瓦定理是指在△ABC内任取一点O,延长AO、BO、CO分别交对边于D、E、F,则(BD/DC)×(CE/EA)×(AF/FB)=1
即:BD*CE*AF=DC*EA*FB;
本题f(x)=(t1-x)(t2-x)(t3-x)=x^3;
求方程在[0,min(t1,min(t2,t3))]的解,误差在1e-5内.
然后就是套二分法求三次方程模板了。。。
以下AC代码:
#include<stdio.h>
#include<math.h>
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{
int t;
int t1,t2,t3;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&t1,&t2,&t3);
double f1=t1*t2*t3;
int t=min(t1,min(t2,t3));
double x1=0,x2=t;
double f2=(t1-x2)*(t2-x2)*(t3-x2)-x2*x2*x2;
if(f1*f2>0)
{
printf("NO\n");
continue;
}
else if(f1==0)
{
printf("YES ");
printf("%.4lf\n",x1);
}
else if(f2==0)
{
printf("YES ");
printf("%.4lf\n",x2);
}
double x0,f0;
int flag=0;
do{
x0=(x1+x2)/2;
f0=(t1-x0)*(t2-x0)*(t3-x0)-x0*x0*x0;
if(f0*f1<0)
{
x2=x0;
f2=f0;
}
else if(f0*f2<0)
{
x1=x0;
f1=f0;
}
else
{
printf("YES ");
printf("%.4lf\n",x0);
flag=1;
break;
}
}while(fabs(f0)>1e-5);
if(!flag)
{
printf("YES ");
printf("%.4lf\n",x0);
}
}
return 0;
}