BIGZHUGOD and His Friends II
1000 ms 65536 KiBDescription
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
Copy2
1 1 1
3 4 6
Output
CopyYES 0.5000
YES 2.0000
Source
鬼知道的
塞瓦定理
没见过 涨姿势了 https://baike.baidu.com/item/%E5%A1%9E%E7%93%A6%E5%AE%9A%E7%90%86/2675177?fr=aladdin
就是三个人站在了一个三角形的三个端点,问你有没有可能使三个人的目光交与一点,有这个定理可以看出来肯定可以,那就二分呗,主要是精度问题。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
double t1,t2,t3;
scanf("%lf%lf%lf",&t1,&t2,&t3);
double high=min(t1,min(t2,t3));
double low=0;
double mid;
double f;
do{
mid=(high+low)*0.5;
// printf("mid:%lf\n",mid);
f=(t1-mid)*(t2-mid)*(t3-mid)-mid*mid*mid;
// printf("~%lf\n",f);
if(f>0.0)
low=mid;
else if(f<0)
high=mid;
}while(abs(f)>1e-9);
printf("YES %.4lf\n",mid);
}
return 0;
}
本文介绍了一个基于三角形场地的游戏寻路问题,通过分析三位玩家移动的时间,利用二分查找算法确定主角能否在特定时刻阻挡玩家视线,从而赢得游戏。文章包含完整的算法实现代码。
175

被折叠的 条评论
为什么被折叠?



