http://www.lightoj.com/volume_showproblem.php?problem=1062
题意:问两条平行边间的距离,给出从同一水平面出发的两条相交线段长,及它们交点到水平面的高。
思路:计算几何怎么可能直接算出答案orz解了好久方程觉得不对,应该是二分枚举平行边的距离,通过相似三角形,算出交点的高,与题目比较,小于误差范围就行了。
/** @Date : 2016-12-10-18.18 * @Author : Lweleth ([email protected]) * @Link : https://github.com/ * @Version : */ #include<bits/stdc++.h> #define LL long long #define PII pair #define MP(x, y) make_pair((x),(y)) #define fi first #define se second #define PB(x) push_back((x)) #define MMG(x) memset((x), -1,sizeof(x)) #define MMF(x) memset((x),0,sizeof(x)) #define MMI(x) memset((x), INF, sizeof(x)) using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5+20; const double eps = 1e-8; int main() { int T; int cnt = 0; cin >> T; while(T--) { double x, y, c; scanf("%lf%lf%lf", &x ,&y ,&c); double h1, h2, m; double s = 0; double l = 0, r = min(x, y); while(r - l > eps) { m = (l + r) / 2.00; //cout << m << " "; h1 = sqrt(x * x - m * m); h2 = sqrt(y * y - m * m); s = h1 * h2 / (h1 + h2); //cout << s << " "; if(fabs(s - c) <= eps) break; else if(s < c) r = m; else if(s > c) l = m; } printf("Case %d: %.8lf\n", ++cnt, m); } return 0; }
时间: 2024-09-30 10:18:45