QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649549 | #9434. Italian Cuisine | Longvu | WA | 63ms | 5872kb | C++14 | 4.9kb | 2024-10-18 01:39:30 | 2024-10-18 01:39:30 |
Judging History
answer
/**
* author: longvu
* created: 10/17/24 21:39:48
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
const int INF = numeric_limits<int>::max();
const int nax = (int)(2010001);
const int mod = 1e9 + 7;
template<class X, class Y>
bool maximize(X& x, const Y y) {
if (y > x) {x = y; return true;}
return false;
}
template<class X, class Y>
bool minimize(X& x, const Y y) {
if (y < x) {x = y; return true;}
return false;
}
struct Point {
ld x, y;
};
using Vtor = Point;
Vtor make_vtor(Point a, Point b) {
return {b.x - a.x, b.y - a.y};
}
int cross(Vtor a, Vtor b) {
return a.x * b.y - a.y * b.x;
}
const ld Exp = (ld)(1e-12);
const ld pi = acos(-1);
struct Segment {
Point a, b;
};
const ld delta = (ld)(0.00000005);
ld sqr(ld z) {
return z * z;
}
ld cal_dist(Point a, Point b) {
return sqrt(sqr(b.x - a.x) + sqr(b.y - a.y));
}
ld cal_min_dist_point_to_segment(Point z, Segment g) {
ld res = INF;
Point u = g.a, v = g.b;
minimize(res, min(cal_dist(z, u), cal_dist(z, v)));
if (abs(u.x - v.x) < Exp) {
Point vec = {v.x - u.x, v.y - u.y};
tuple<ld, ld, ld> lnp = {vec.x, vec.y, vec.x * z.x + vec.y * z.y};
swap(vec.x, vec.y);
vec.x *= -1;
tuple<ld, ld, ld> ln = {vec.x, vec.y, vec.x * u.x + vec.y * u.y};
Point g = {0, (get<2>(ln) * get<0>(lnp) - get<0>(ln) * get<2>(lnp)) / (get<0>(lnp) * get<1>(ln) - get<0>(ln) * get<1>(lnp))};
// cout << setprecision(4) << xxed << get<0>(ln) << " " << get<1>(ln) << " " << get<2>(ln) << '\n';
// cout << setprecision(4) << xxed << get<0>(lnp) << " " << get<1>(lnp) << " " << get<2>(lnp) << '\n';
g.x = (get<2>(ln) - get<1>(ln) * g.x) / get<0>(ln);
// cout << u.x << " " << u.y << " " << v.x << " " << v.y << '\n';
Point t = g;
maximize(t.x, min(u.x, v.x));
minimize(t.x, max(u.x, v.x));
maximize(t.y, min(u.y, v.y));
minimize(t.y, max(u.y, v.y));
if (abs(t.x - g.x) < Exp && abs(t.y - g.y) < Exp) {
minimize(res, cal_dist(z, g));
}
} else {
Point vec = {v.x - u.x, v.y - u.y};
tuple<ld, ld, ld> lnp = {vec.x, vec.y, vec.x * z.x + vec.y * z.y};
swap(vec.x, vec.y);
vec.x *= -1;
tuple<ld, ld, ld> ln = {vec.x, vec.y, vec.x * u.x + vec.y * u.y};
Point g = {(get<2>(ln) * get<1>(lnp) - get<1>(ln) * get<2>(lnp)) / (get<1>(lnp) * get<0>(ln) - get<1>(ln) * get<0>(lnp)), 0};
// cout << setprecision(4) << xxed << get<0>(ln) << " " << get<1>(ln) << " " << get<2>(ln) << '\n';
// cout << setprecision(4) << xxed << get<0>(lnp) << " " << get<1>(lnp) << " " << get<2>(lnp) << '\n';
g.y = (get<2>(ln) - get<0>(ln) * g.x) / get<1>(ln);
// cout << u.x << " " << u.y << " " << v.x << " " << v.y << '\n';
Point t = g;
maximize(t.x, min(u.x, v.x));
minimize(t.x, max(u.x, v.x));
maximize(t.y, min(u.y, v.y));
minimize(t.y, max(u.y, v.y));
if (abs(t.x - g.x) < Exp && abs(t.y - g.y) < Exp) {
minimize(res, cal_dist(z, g));
}
}
return res;
}
Point a[nax];
int pre[nax];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
Point b;
int d;
cin >> b.x >> b.y >> d;
for (int i = 0; i < n; ++i) {
cin >> a[i].x >> a[i].y;
a[n + i] = a[i];
}
for (int i = 0; i < 2 * n - 1; ++i) {
pre[i] = cross(a[i], a[i + 1]);
if (i) {
pre[i] += pre[i - 1];
}
}
auto ck = [&](Point x, Point y, Point z) {
int sum = abs(cross(make_vtor(b, x), make_vtor(b, y))
+ cross(make_vtor(b, y), make_vtor(b, z))
+ cross(make_vtor(b, z), make_vtor(b, x)));
int sump = abs(cross(make_vtor(b, x), make_vtor(b, y)))
+ abs(cross(make_vtor(b, y), make_vtor(b, z)))
+ abs(cross(make_vtor(b, z), make_vtor(b, x)));
return sum != sump;
};
int j = 0, ans = 0;
for (int i = 0; i < n; ++i) {
j = i + 1;
while (ck(a[i], a[j], a[j + 1])
&& cal_min_dist_point_to_segment(b, {a[i], a[j + 1]}) > d) {
j++;
}
assert(j < 2 * n);
int sum = abs(pre[j - 1] - (!i ? 0 : pre[i - 1])
+ cross(a[j], a[i]));
// cout << i << " " << j << " " << sum << '\n';
maximize(ans, sum);
}
cout << ans << '\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5864kb
input:
3 5 1 1 1 0 0 1 0 5 0 3 3 0 5 6 2 4 1 2 0 4 0 6 3 4 6 2 6 0 3 4 3 3 1 3 0 6 3 3 6 0 3
output:
5 24 0
result:
ok 3 number(s): "5 24 0"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
1 6 0 0 499999993 197878055 -535013568 696616963 -535013568 696616963 40162440 696616963 499999993 -499999993 499999993 -499999993 -535013568
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 63ms
memory: 5872kb
input:
6666 19 -142 -128 26 -172 -74 -188 -86 -199 -157 -200 -172 -199 -186 -195 -200 -175 -197 -161 -188 -144 -177 -127 -162 -107 -144 -90 -126 -87 -116 -86 -104 -89 -97 -108 -86 -125 -80 -142 -74 -162 -72 16 -161 -161 17 -165 -190 -157 -196 -154 -197 -144 -200 -132 -200 -128 -191 -120 -172 -123 -163 -138...
output:
5093 2862 2539 668 3535 7421 4883 5711 5624 1034 2479 3920 4372 2044 4996 5070 2251 4382 4175 1489 1154 3231 4038 1631 5086 14444 1692 6066 687 1512 4849 5456 2757 8341 8557 8235 1013 5203 10853 6042 6300 4480 2303 2728 1739 2187 3385 4266 6322 909 4334 1518 948 5036 1449 2376 3180 4810 1443 1786 47...
result:
wrong answer 2nd numbers differ - expected: '3086', found: '2862'