CF1555B题解

  • 分析

    放桌子有两种放法,一种是上下放,一种是左右放,分别计算最小值取 \(\min\) 即可。
    注意到原题使用的是平面直角坐标系,于是将原图顺时针旋转 \(90^{\circ}\),将下标表示方式与代码中下标的表示方式统一,相应的,左下角和右上角也变成了左上角和右下角。

  • 代码

#include <iostream>
using namespace std;
constexpr int MAXN(1000007);
constexpr int INF(0x3f3f3f3f);
int T, n, m, x1, y1, x2, y2, x3, y3, x4, y4, sx, zy;
inline void read(int &temp) { cin >> temp; }
inline void work() {
	int ans(INF);
	read(n), read(m);
	read(x1), read(y1), read(x2), read(y2);
	sx = max(x1, n - x2), zy = max(y1, m - y2);
	read(x3), read(y3);
	if (x3 + x2 - x1 <= n) {
		if (sx >= x3)  ans = min(ans, 0);
		else  ans = min(ans, x3 - sx);
	}
	if (y3 + y2 - y1 <= m) {
		if (zy >= y3)  ans = min(ans, 0);
		else  ans = min(ans, y3 - zy);
	}
	if (ans == INF)  return cout << "-1" << endl, void();
	return cout << ans << ".000000000" << endl, void();
}
int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	read(T);
	while (T--)  work();
	return 0;
}
posted @ 2023-10-25 16:08  Kazdale  阅读(181)  评论(0编辑  收藏  举报