QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356771 | #6436. Paimon Polygon | PorNPtree | WA | 1ms | 6192kb | C++14 | 4.9kb | 2024-03-18 11:26:13 | 2024-03-18 11:26:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
pair<int, int> operator - (pair<int, int> x, pair<int, int> y)
{
return make_pair(x.first - y.first, x.second - y.second);
}
int operator * (pair<int, int> x, pair<int, int> y)
{
return x.first * y.second - x.second * y.first;
}
double atan3(int y, int x)
{
double f = atan2(y, x);
return (f > -1e-6 ? f : f + 2 * acos(-1.0));
}
int cmp(pair<int, int> x, pair<int, int> y)
{
return atan3(x.second, x.first) < atan3(y.second, y.first);
}
pair<int, int> jz;
int cmp2(pair<int, int> x, pair<int, int> y)
{
return cmp(x - jz, y - jz);
}
int flag, S[N], top, vis[N];
pair< vector< pair<int, int> >, vector< pair<int, int> > > convexHull(vector< pair<int, int> > z)
{
for (int i = 1; i < (int)z.size(); ++i) {
if (z[i].second < z[0].second || (z[i].second == z[0].second && z[i].first < z[0].first)) {
swap(z[0], z[i]);
}
}
jz = z[0];
sort(z.begin() + 1, z.end(), cmp2);
S[top = 1] = 0;
for (int i = 1; i < (int)z.size(); ++i) {
while (top >= 2 && (z[S[top]] - z[S[top - 1]]) * (z[i] - z[S[top]]) < 0) {
--top;
}
S[++top] = i;
}
for (int i = 0; i < (int)z.size(); ++i) {
vis[i] = 0;
}
if (top <= 2) {
flag = 0;
return {{}, {}};
}
vector< pair<int, int> > S1, S2;
for (int i = 1; i <= top; ++i) {
S1.push_back(z[S[i]]);
vis[S[i]] = 1;
if ((z[S[i]] - z[S[(i == 1 ? top : i - 1)]]) * (z[S[(i == 1 ? top : i - 1)]] - z[S[(i == 1 ? top - 1 : (i == 2 ? top : i - 2))]]) == 0) {
flag = 0;
return {{}, {}};
}
}
for (int i = 0; i < (int)z.size(); ++i) {
if (!vis[i]) {
S2.push_back(z[i]);
}
}
return make_pair(S1, S2);
}
double jerry(vector< pair<int, int> > z)
{
double res = 0;
for (int i = 0; i < (int)z.size(); ++i) {
int j = (i + 1 == (int)z.size() ? 0 : i + 1);
res += hypot(z[i].first - z[j].first, z[i].second - z[j].second);
}
return res;
}
signed main()
{
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
vector< pair<int, int> > z, tz;
for (int i = 1, x, y; i <= n; ++i) {
scanf("%d%d", &x, &y);
z.emplace_back(x, y);
}
flag = 1;
tz = z;
z.emplace_back(0, 0);
pair< vector< pair<int, int> >, vector< pair<int, int> > > tmp = convexHull(z);
double res = 0;
if (flag) {
vector< pair<int, int> > p1 = tmp.first, p2 = tmp.second, p3;
int hv = 0;
for (int i = 0; i < (int)p1.size(); ++i) {
hv |= (p1[i] == make_pair(0, 0));
}
if (hv) {
p2.emplace_back(0, 0);
if ((int)p2.size() >= 3) {
tmp = convexHull(p2);
p2 = tmp.first, p3 = tmp.second;
if (flag && p3.empty()) {
res = max(res, jerry(p1) + jerry(p2));
}
}
}
}
z.pop_back();
sort(z.begin(), z.end(), cmp);
vector<int> hv;
for (int i = 0; i < (int)z.size(); ++i) {
if ((z[i] - z[(i + n - 1) % n]) * (z[(i + 1) % n] - z[i]) <= 0) {
hv.push_back(i);
}
}
if ((int)hv.size() > 4) {
printf("%.10lf\n", res);
continue;
}
double ts = jerry(z);
for (int i = 0, j = 1; i < (int)z.size(); ++i) {
while ((j + 1) % n != i && (make_pair(0, 0) - z[i]) * z[(j + 1) % n] <= 0) {
j = (j + 1) % n;
}
if ((make_pair(0, 0) - z[i]) * z[(j + 1) % n] <= 0 || (make_pair(0, 0) - z[j]) * z[(i + 1) % n] <= 0 ||
(make_pair(0, 0) - z[i]) * z[(i + 1) % n] == 0 || (make_pair(0, 0) - z[j]) * z[(j + 1) % n] == 0) {
continue;
}
int ok = 1;
for (auto x : hv) {
if (x != i && x != j && x != (i + 1) % n && x != (j + 1) % n) {
ok = 0;
break;
}
}
if (ok) {
res = max(res, ts + hypot(z[i].first, z[i].second)
+ hypot(z[(i + 1) % n].first, z[(i + 1) % n].second)
+ hypot(z[j].first, z[j].second)
+ hypot(z[(j + 1) % n].first, z[(j + 1) % n].second)
- hypot(z[i].first - z[(i + 1) % n].first, z[i].second - z[(i + 1) % n].second)
- hypot(z[j].first - z[(j + 1) % n].first, z[j].second - z[(j + 1) % n].second));
}
}
printf("%.10lf\n", res);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6148kb
input:
3 4 0 3 3 0 2 3 3 2 5 4 0 5 -5 -4 -2 1 -2 -5 -2 4 0 1 1 0 0 2 1 1
output:
17.2111025509 36.6326947621 0.0000000000
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 6152kb
input:
14 4 0 3 1 3 3 1 3 0 4 -4 0 5 3 0 -4 -1 0 5 4 4 5 0 3 3 3 2 -4 2 5 1 1 2 4 1 4 0 4 -1 1 4 4 5 -2 4 1 4 -5 -2 5 3 5 3 -1 4 -5 4 1 2 4 5 4 0 5 -5 -4 -2 1 -2 -5 -2 5 3 4 3 5 -5 -1 1 2 4 1 5 -5 -3 3 -3 -3 -3 2 -3 -4 5 5 0 1 -3 -1 -3 -3 -4 -4 -3 0 6 1 -3 -3 -3 2 -2 -3 1 -4 -5 3 -3 6 -1 -4 -3 0 0 4 -4 -3 ...
output:
14.3245553203 0.0000000000 30.6896447944 18.7482240257 30.2540122179 27.8210682918 36.6326947621 33.4097258671 29.5562146354 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000
result:
ok 14 numbers
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 6192kb
input:
100 6 -4 1 -1 4 1 4 -4 -1 -2 3 3 2 7 -5641417 962017 -5641417 -962017 -5719589 193284 -5693492 -578972 -5693492 578972 -5563601 1340673 -5719589 -193284 9 -25 55 58 15 -13 14 -1 19 -60 6 -17 8 11 15 16 58 16 11 10 398546 -221163 -87181 -447383 -221163 -398546 -467649 -57196 55334 -452427 -427086 -19...
output:
25.1141680517 0.0000000000 359.1097585858 0.0000000000 547.7541625009 62188.8862666670 42738252.5221139938 0.0000000000 2793294108.4426059723 69911.1777695327 0.0000000000 27901.9604859406 0.0000000000 0.0000000000 686502.0611442826 33588141.0647002682 0.0000000000 32286.4991917329 0.0000000000 3082...
result:
wrong answer 2nd numbers differ - expected: '24824262.6835848', found: '0.0000000', error = '1.0000000'