题目链接:http://lightoj.com/volume_showproblem.php?problem=1385
题意:下图中已知面积 a b c 求 d; 如果d的面积不确定,输出-1。
连接AX,记△AFX的面积为m,△AEX的面积为n。
因为△AFX与△BFX共高线,所以m/a = AF/FB;
又因为(n+c)与b共底边,高线所在的三角形相似,高线只比为AF/FB = (n+c)/b = m/a。
同理可得(m+a)/b = n/c = AE/CE
然后解二元一次方程组求得
m = (abc+ac2)/(b2-ac);
n = (abc+a2c)/(b2-ac);
当b2-ac=0时答案为-1;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<set> using namespace std; #define met(a, b) memset(a, b, sizeof(a)) #define maxn 10005 #define maxm 20005 #define INF 0x3f3f3f3f typedef long long LL; int main() { int T, t = 1; double a, b, c; scanf("%d", &T); while(T--) { scanf("%lf %lf %lf", &a, &b, &c); if(b*b - a*c <1e-7) printf("Case %d: -1 ", t++); else printf("Case %d: %.6f ", t++, (a*a*c+a*c*c+2*a*b*c)/(b*b-a*c)); } return 0; }