QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649544 | #9434. Italian Cuisine | Longvu | WA | 1ms | 5892kb | C++14 | 4.9kb | 2024-10-18 01:34:51 | 2024-10-18 01:34:52 |
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: 1ms
memory: 5772kb
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: -100
Wrong Answer
time: 1ms
memory: 5892kb
input:
1 6 0 0 499999993 197878055 -535013568 696616963 -535013568 696616963 40162440 696616963 499999993 -499999993 499999993 -499999993 -535013568
output:
286862654137719264
result:
wrong answer 1st numbers differ - expected: '0', found: '286862654137719264'