题意等价于求 。
令 即可消去分子中的 。
把 拆开 分别做,考虑使用分数规划解决,判定形如 ,发现相当于 ,然后判定是否存在一组 ,满足 。
然后发现这个 不需要限定为非负整数,而是任意非负实数均可,原因是有一组非负实数解必定可以找到相应的非负整数解。
问题可以继续转化为给定一堆向量 ,问是否存在一组数 ,满足 在第三象限。
本来就存在向量在第三象限显然合法,如果不存在只需要判定是否存在分别处于第二、第四象限的两个向量,满足他俩过第三象限的夹角小于 。
#include "bits/stdc++.h"
#define f(i ,m ,n ,x) for (int i = (m) ,i##END = (n) ; i <= i##END ; i += (x))
const int N = 2e5 + 25 ;
const double pi = std :: acos (-1.0) ;
int n ; double a[N] ,b[N] ,c[N] ,A[N] ,B[N] ;
int main (void) {
std :: ios :: sync_with_stdio (false) ,
std :: cin.tie (nullptr) ,std :: cout.tie (nullptr) ;
std :: cin >> n ; f (i ,1 ,n ,1)
std :: cin >> a[i] >> b[i] >> c[i] ,a[i] /= c[i] ,b[i] /= c[i] ;
double l = 0.0 ,r = 1e9 ,ans ; f (i ,1 ,55 ,1) {
double mid = (l + r) / 2.0 ;
double theta1 = pi / 2.0 ,theta2 = pi / 2.0 ; bool ok (false) ;
f (i ,1 ,n ,1) {
A[i] = a[i] - mid ,B[i] = b[i] - mid ;
if (A[i] <= 0 && B[i] <= 0) { ok = true ; break ;}
if (A[i] <= 0)
theta1 = std :: min (theta1 ,std :: atan (-B[i] / A[i])) ;
else if (B[i] <= 0)
theta2 = std :: min (theta2 ,std :: atan (-A[i] / B[i])) ;
} if (ok) goto her ;
ok = theta1 + theta2 < pi / 2.0 ; her : ;
if (ok) r = ans = mid ; else l = mid ;
} std :: cout << std :: fixed <<
std :: setprecision (6) << 1.0 / ans << '\n' ;
return 0 ;
}