题目分析
一道解析几何题,要考虑多种情况,题目的x,y,xp,yp都大于0,即我们只用考虑4种情况:上,右上,右,包含。
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t;
signed main() {
cin >> t;
while (t--) {
double x, y, xp, yp, ans;
cin >> x >> y >> xp >> yp;
if (xp <= x && yp <= y) {
ans = max(xp, x - xp) * max(yp, y - yp) / (x * y);
} else if (xp >= x && yp >= y) {
ans = x * y / (xp * yp);
} else if (xp >= x && yp <= y) {
ans = max(yp, y - yp) * x / (x * y + max(yp, y - yp) * (xp - x));
} else {
ans = max(xp, x - xp) * y / (x * y + max(xp, x - xp) * (yp - y));
}
cout << fixed << setprecision(9) << ans << endl;
}
return 0;
}
Comments NOTHING