《补题》(牛客:现在是,学术时间(2))

59 阅读1分钟

分类讨论

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 998244353;
void solve() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	if (x2 <= x1) {
		if (y2 <= y1) {
			cout << fixed << setprecision(9) << max(max(x2 * y2, (x1 - x2) * y2), max((x1 - x2) * (y1 - y2), (y1 - y2) * x2)) / (x1 * y1) << endl;
		}
		else {
			if (x2 >= x1 - x2) {
				cout << fixed << setprecision(9) << x2 * y1 / (x1 * y1 + (y2 - y1) * x2) << endl;
			}
			else {
				cout << fixed << setprecision(9) << (x1 - x2) * y1 / (x1 * y1 + (y2 - y1) * (x1 - x2)) << endl;
			}
		}
	}
	else {
		if (y2 >= y1) {
			cout << fixed << setprecision(9) << x1 * y1 / (x2 * y2) << endl;
		}
		else {
			if (y2 >= y1 - y2) {
				cout << fixed << setprecision(9) << x1 * y2 / (x1 * y1 + y2 * (x2 - x1)) << endl;
			}
			else {
				cout << fixed << setprecision(9) << x1 * (y1- y2) / (x1 * y1 + (y1 - y2) * (x2 - x1)) << endl;
			}
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int _ = 1;
	int t;
	cin >> t;
	while (t --) {
		solve();
	}
	return 0;
}