水题
当时没时间了,时间分配还是有问题
把点投影到四边形上,计算到某个顶点的距离,排序
#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
double a1, a2, a3, a4;
int T, w, h, n;
int bx, by;
double angle(int x, int y) {
return atan2(y - by, x - bx);
}
struct Point {
int x, y;
}A[N];
double cal_p(double a) {
if (a < a1 or a >= a4) {
return h - by + tan(a) * bx;
}
if (a >= a1 and a < a2) {
a += pi / 2;
return h + bx + tan(a) * by;
}
if (a >= a2 and a < a3) {
return w + h + by + tan(a) * (w - bx);
}
if (a >= a3 and a < a4) {
a -= pi / 2;
return w - bx + tan(a) * (h - by) + 2 * h + w;
}
}
double d[N];
int main() {
scanf("%d", &T);
for (int c = 1; c <= T; c++) {
scanf("%d%d", &w, &h);
scanf("%d%d", &bx, &by);
a1 = angle(0, 0), a2 = angle(w, 0), a3 = angle(w, h), a4 = angle(0, h);
scanf("%d", &n);
for (int i = 0; i < n; i++)scanf("%d%d", &A[i].x, &A[i].y);
for (int i = 0; i < n; i++) {
d[i] = cal_p(angle(A[i].x, A[i].y));
}
sort(d, d + n);
double ans = 2 * w + 2 * h - d[n - 1] + d[0];
for (int i = 1; i < n; i++) {
ans = max(ans, d[i] - d[i - 1]);
}
printf("Case #%d: %.8f
", c, ans);
}
}