题面
大秦为你打开题目传送门 (看不了的就看下面吧)
看下图

已知三角形 $ABC$ ,$DE$ 平行于 $BC$ ,给定三角形 $ADE$ 与四边形 $BCED$ 的面积之比,求 $AD$ 的长度。
题意
显而易见的,使用相似,这道题可以用数学方法 $O(1)$ 求解。三分的话我们可以直接三分答案拿着算出的答案就去和比例比,就可以了。
代码
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 
 | #include<bits/stdc++.h>using namespace std;
 
 const double eps = 1e-10;
 
 double AB, AC, BC, k;
 
 void Input() {
 scanf("%lf%lf%lf%lf", &AB, &AC, &BC, &k);
 
 }
 
 double calc(double a, double b, double c) {
 double p = (a + b + c) / 2;
 return sqrt(p * (p - a) * (p - b) * (p - c));
 }
 
 bool Check(double AD) {
 double AE = AD / AB * AC;
 double DE = AD / AB * BC;
 double ADE = calc(AD, AE, DE);
 return (ADE / (calc(AB, AC, BC) - ADE)) - k < eps;
 }
 
 void Work() {
 double l = 0, r = AB, best = -1;
 while (l - r < -eps) {
 
 double mid = (l + r) / 2;
 if (Check(mid)) {
 l = mid;
 best = mid;
 }
 else {
 r = mid;
 }
 }
 printf("%.2lf\n", best);
 }
 
 int main() {
 int T, ca = 1;
 scanf("%d", &T);
 while (T--) {
 
 Input();
 printf("Case %d: ", ca++);
 Work();
 }
 return 0;
 }
 
 |