BIGZHUGOD and His Friends II
Problem Description
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.
Input
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).
Output
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".
Sample Input
2 1 1 1 3 4 6
Sample Output
YES 0.5000 YES 2.0000
Hint
Source
题意:有三个人分别在三角形的三个顶点A、B、C,他们以相同的速度从A -> B、B -> C 、C -> A,问是否在某一时刻,三角形的三个顶点与三个人的连线交于一点。。。。
思路:话说就是赛瓦定理,某神跟我说,我可能不搞数竞,这样子的题目,不知道就是不知道了,那我之后记住他吧!!!
这样只需要二分枚举一下吧!!
公式:AF*BD*CE = FB*DC*EA;
AC代码:
#include<bits/stdc++.h>
#define mid ((l+r)/2)
using namespace std;
int t;
double l = 0, r, tmp, t1, t2, t3;
double min(double a, double b, double c)
{
a = min(a, b);
a = min(a, c);
return a;
}
double solve(double k)
{
return (t1-k)*(t2-k)*(t3-k)-k*k*k;
}
int main(){
scanf("%d",&t);
while(t--){
l = 0;
scanf("%lf%lf%lf",&t1, &t2, &t3);
r = min(t1, t2, t3);
while(fabs(r-l)>1e-9){
tmp = solve(mid);
if(fabs(tmp) < 1e-9)break;
if(tmp > 0)l = mid;
else r = mid;
}
printf("YES %0.4f\n",mid);
}
return 0;
}