山东省第六届ACM省赛题——BIGZHUGOD and His Friends II(塞瓦定理,二分求解方程)

19 篇文章 1 订阅
17 篇文章 0 订阅

题目描述
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

要不是知道有个塞瓦定理谁会写这道题?

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <set>
#include <vector>
#include <iomanip>
#include <stack>
#include <map>
#include <queue>
#define MAXN 100010
#define mod 9973
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    int t,t1,t2,t3;
    cin>>t;
    while(t--)
    {
        cin>>t1>>t2>>t3;
        double low=0,high=min(t1,min(t2,t3)),mid;
        double f0;
        do
        {
            mid=(low+high)*0.5;
            f0=(t1-mid)*(t2-mid)*(t3-mid)-mid*mid*mid;
            if(f0>0)
                low=mid;
            else if(f0<0)
                high=mid;
        }while(fabs(f0)>1e-9);
        cout<<"YES "<<setiosflags(ios::fixed)<<setprecision(4)<<mid<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值