山东省第六届省赛 BIGZHUGOD and His Friends II(赛瓦定理)

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

 

题解:

赛瓦定理+二分精度求解

代码:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define is_lower(c) (c >= 'a' && c <= 'z')
#define is_upper(c) (c >= 'A' && c <= 'Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c >= '0' && c <= '9')
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define PI acos(-1)
#define IO                 \
  ios::sync_with_stdio(0); \
  cin.tie(0);              \
  cout.tie(0);
#define For(i, a, b) for (int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const ll inf = 0x3f3f3f3f;
const double EPS = 1e-10;
const ll inf_ll = (ll)1e18;
const ll maxn = 100005LL;
const ll mod = 1000000007LL;
const int N = 50 + 5;
int main() {
  int T;
  cin >> T;
  double t1, t2, t3;
  while (T--) {
    cin >> t1 >> t2 >> t3;
    // 2t^3 = t1*t2*t3 - (t1 * t2 + t2 * t3 + t3 * t1) * t +
    // (t1 + t2 + t3) * t^2;
    double l = 0, r = min(t1, min(t2, t3)), t;
    while (fabs(r - l) > 1e-9) {
      t = (l + r) / 2.0;
      double y = t1 * t2 * t3 - (t1 * t2 + t2 * t3 + t3 * t1) * t +
                 (t1 + t2 + t3) * t * t - t * t * t * 2;
      if (y > 0)
        l = t;
      else
        r = t;
    }
    printf("YES %.4lf\n", t);
  }
}

 

posted @ 2018-03-22 12:55  GHzz  阅读(195)  评论(0编辑  收藏  举报