QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182806 | #6752. Geometry | ucup-team004# | AC ✓ | 19ms | 4052kb | C++20 | 2.3kb | 2023-09-18 16:02:43 | 2023-09-18 16:02:43 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
struct Point {
int x = 0;
int y = 0;
};
Point operator-(const Point &a, const Point &b) {
return {a.x - b.x, a.y - b.y};
}
int cross(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
int dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<std::array<Point, 3>> a(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
std::cin >> a[i][j].x >> a[i][j].y;
}
}
std::vector<double> f(1 << n);
for (int s = 1; s < (1 << n); s++) {
std::vector<Point> ps;
for (int i = 0; i < n; i++) {
if (s >> i & 1) {
for (int j = 0; j < 3; j++) {
ps.push_back(a[i][j]);
}
}
}
std::sort(ps.begin(), ps.end(),
[&](const Point &a, const Point &b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
});
std::vector<Point> h, l;
for (auto p : ps) {
while (h.size() > 1 && cross(h.back() - h[h.size() - 2], p - h.back()) >= 0) {
h.pop_back();
}
h.push_back(p);
while (l.size() > 1 && cross(l.back() - l[l.size() - 2], p - l.back()) <= 0) {
l.pop_back();
}
l.push_back(p);
}
for (int i = 1; i < h.size(); i++) {
f[s] += std::sqrt(dot(h[i - 1] - h[i], h[i - 1] - h[i]));
}
for (int i = 1; i < l.size(); i++) {
f[s] += std::sqrt(dot(l[i - 1] - l[i], l[i - 1] - l[i]));
}
}
std::vector<double> dp(1 << n, 1E9);
dp[0] = 0;
for (int s = 1; s < (1 << n); s++) {
int u = __builtin_ctz(s);
int ns = s ^ (1 << u);
for (int t = ns; ; t = (t - 1) & ns) {
dp[s] = std::min(dp[s], dp[t] + f[s ^ t]);
if (!t) {
break;
}
}
}
std::cout << std::fixed << std::setprecision(10);
std::cout << dp.back() << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
2 0 0 1 0 0 1 100 100 101 100 100 101
output:
6.8284271247
result:
ok found '6.82843', expected '6.82843', error '0.00000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
2 0 0 0 1 1 0 1 0 0 1 1 1
output:
4.0000000000
result:
ok found '4.00000', expected '4.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 17ms
memory: 4052kb
input:
14 3 0 0 2 0 1 3 3 2 0 0 1 2 0 3 2 2 0 3 2 3 1 0 3 0 0 1 3 1 2 3 2 2 2 0 1 1 2 1 0 3 2 0 0 0 3 3 2 2 1 3 2 2 2 2 1 0 1 1 0 2 0 3 2 0 2 0 2 3 1 3 3 1 2 0 2 2 0 3 3 3 1 3 1
output:
12.0000000000
result:
ok found '12.00000', expected '12.00000', error '0.00000'
Test #4:
score: 0
Accepted
time: 17ms
memory: 3804kb
input:
14 1 2 3 1 0 3 2 1 1 6 2 1 0 5 4 1 1 0 5 6 6 5 2 0 6 6 1 2 0 0 0 0 4 6 1 2 5 2 2 3 0 6 3 1 0 2 3 4 0 0 5 1 5 2 0 6 6 6 3 5 6 1 0 3 2 0 2 1 4 5 6 3 5 2 2 5 2 6 1 4 4 2 4 2
output:
23.1231056256
result:
ok found '23.12311', expected '23.12311', error '0.00000'
Test #5:
score: 0
Accepted
time: 18ms
memory: 3808kb
input:
14 9 1 9 3 4 1 0 6 0 2 0 3 0 0 1 5 8 2 9 1 4 2 1 5 1 0 6 6 5 4 3 1 4 2 1 6 1 5 1 8 6 9 6 3 1 8 2 2 6 8 0 3 8 5 0 4 4 7 2 6 4 7 2 8 4 7 6 7 5 5 2 1 2 7 0 7 0 4 8 0 7 5 2 2
output:
31.6356505708
result:
ok found '31.63565', expected '31.63565', error '0.00000'
Test #6:
score: 0
Accepted
time: 18ms
memory: 4044kb
input:
14 12 12 5 8 4 4 12 1 12 8 3 1 0 10 10 10 10 12 9 2 8 3 5 4 8 9 5 3 8 2 9 9 0 7 8 4 5 2 0 10 4 8 10 4 8 8 2 3 9 5 9 10 1 10 3 5 12 6 5 6 9 0 8 5 1 7 4 11 10 11 6 12 6 11 2 11 10 4 11 3 6 7 12 5
output:
42.3124177261
result:
ok found '42.31242', expected '42.31242', error '0.00000'
Test #7:
score: 0
Accepted
time: 14ms
memory: 3888kb
input:
14 5 5 0 13 4 11 5 8 6 13 11 8 1 15 12 4 2 10 7 7 7 11 11 0 6 1 0 0 5 3 14 15 0 8 3 8 6 14 1 8 12 4 14 3 8 15 3 15 7 9 13 7 8 13 15 9 14 12 14 8 2 11 4 11 15 2 14 13 4 15 14 11 6 1 9 8 11 14 9 12 0 14 13 1
output:
56.9691120477
result:
ok found '56.96911', expected '56.96911', error '0.00000'
Test #8:
score: 0
Accepted
time: 18ms
memory: 3744kb
input:
14 0 13 2 13 18 8 10 6 3 13 13 3 12 12 13 17 7 18 2 14 18 17 2 11 5 15 6 3 3 4 2 5 17 3 0 10 10 13 15 11 8 9 9 14 4 1 3 15 2 6 2 0 14 15 14 16 18 9 16 7 8 7 17 13 10 3 6 11 3 4 18 13 4 1 13 14 9 17 14 14 14 15 1 1
output:
62.5133630391
result:
ok found '62.51336', expected '62.51336', error '0.00000'
Test #9:
score: 0
Accepted
time: 17ms
memory: 3800kb
input:
14 14 3 16 12 20 0 5 3 19 18 21 4 2 1 4 16 11 2 5 14 3 16 6 2 0 10 8 19 1 20 0 14 9 18 20 7 12 5 16 4 13 6 12 9 13 21 7 13 10 13 11 16 19 11 16 10 16 16 9 17 13 9 18 18 12 0 6 3 1 19 8 20 2 6 2 7 13 0 3 6 10 3 3 2
output:
74.3672223694
result:
ok found '74.36722', expected '74.36722', error '0.00000'
Test #10:
score: 0
Accepted
time: 18ms
memory: 3932kb
input:
14 19 0 22 1 10 2 7 0 13 4 18 23 12 8 13 14 0 0 2 11 7 17 24 21 16 4 17 18 0 10 17 3 20 10 16 8 9 17 21 8 0 16 13 23 23 7 17 16 9 17 21 0 21 7 20 18 5 8 4 15 11 6 14 8 6 14 4 21 12 18 15 24 10 23 12 2 9 1 10 13 12 8 18 14
output:
85.8461769922
result:
ok found '85.84618', expected '85.84618', error '0.00000'
Test #11:
score: 0
Accepted
time: 17ms
memory: 3936kb
input:
14 19 19 22 26 11 24 6 0 22 26 8 13 15 21 9 10 18 25 12 2 11 3 26 16 24 4 20 3 7 24 12 9 6 12 8 20 13 9 17 0 4 23 5 20 10 19 10 24 27 9 14 21 7 6 17 13 1 8 5 19 5 1 17 8 10 27 21 17 16 8 4 11 27 6 27 5 6 15 20 25 21 0 11 7
output:
88.6778740832
result:
ok found '88.67787', expected '88.67787', error '0.00000'
Test #12:
score: 0
Accepted
time: 19ms
memory: 3824kb
input:
14 16 22 6 0 8 27 4 29 30 7 2 11 27 9 13 12 13 7 23 24 26 2 21 15 21 21 0 29 27 3 27 27 21 6 14 10 12 19 25 29 25 21 18 9 11 2 23 24 2 3 29 17 6 25 9 25 20 2 16 6 6 27 2 17 17 29 28 2 21 22 8 12 18 6 18 30 11 27 26 9 3 16 7 5
output:
106.7278624246
result:
ok found '106.72786', expected '106.72786', error '0.00000'
Test #13:
score: 0
Accepted
time: 14ms
memory: 3756kb
input:
14 1 19 18 19 7 20 3 29 22 1 14 13 12 18 9 23 8 4 4 1 2 2 16 2 25 12 16 3 12 13 7 26 1 13 16 19 0 5 15 25 17 1 3 16 4 28 10 9 10 9 7 2 11 27 22 1 0 15 17 31 2 3 16 26 15 33 17 8 11 23 15 15 10 27 22 1 26 32 12 2 30 8 0 8
output:
106.8151079080
result:
ok found '106.81511', expected '106.81511', error '0.00000'
Test #14:
score: 0
Accepted
time: 17ms
memory: 3800kb
input:
14 16 31 30 12 23 4 29 2 32 24 17 16 3 11 28 12 16 5 1 20 30 35 25 13 24 12 26 27 3 7 8 12 5 30 21 1 10 22 4 22 30 9 18 32 27 18 17 5 2 36 9 12 18 30 17 30 14 24 17 3 1 14 9 7 24 23 16 20 33 34 28 21 33 12 12 4 21 30 14 35 29 12 7 17
output:
120.2977118672
result:
ok found '120.29771', expected '120.29771', error '0.00000'
Test #15:
score: 0
Accepted
time: 17ms
memory: 3836kb
input:
14 13 18 6 21 16 9 27 17 22 20 10 12 39 33 14 27 15 0 11 35 12 38 4 9 27 3 21 16 28 27 26 22 9 17 14 7 19 39 37 25 29 7 19 22 23 21 10 14 5 10 31 18 13 3 37 2 5 24 18 31 18 38 29 34 26 6 38 35 27 27 14 11 33 15 11 35 36 31 13 10 7 19 4 11
output:
126.7823458532
result:
ok found '126.78235', expected '126.78235', error '0.00000'
Test #16:
score: 0
Accepted
time: 14ms
memory: 3800kb
input:
14 20 0 22 13 27 35 41 10 2 37 30 6 33 15 31 0 30 33 11 25 6 12 18 33 10 21 22 38 39 18 11 27 21 34 19 17 24 11 17 23 21 21 35 20 16 5 18 21 0 13 39 10 11 17 21 33 18 32 18 1 17 40 31 9 6 42 18 24 26 10 42 16 39 9 22 19 2 21 38 8 2 29 38 36
output:
138.5345634476
result:
ok found '138.53456', expected '138.53456', error '0.00000'
Test #17:
score: 0
Accepted
time: 18ms
memory: 3824kb
input:
14 19 29 27 25 7 23 12 7 38 13 28 5 31 15 37 11 12 39 19 42 6 34 27 4 43 45 16 14 23 31 28 41 45 33 31 2 36 23 11 35 18 24 22 19 15 41 41 3 31 34 2 17 35 16 6 40 1 37 1 28 37 15 23 6 10 27 20 26 34 1 42 18 35 44 17 11 18 36 15 2 4 21 40 12
output:
151.8028902773
result:
ok found '151.80289', expected '151.80289', error '0.00000'
Test #18:
score: 0
Accepted
time: 17ms
memory: 3824kb
input:
14 4 22 11 24 13 30 47 46 17 4 42 47 14 7 21 40 8 10 15 42 28 40 33 6 45 27 16 4 9 19 17 35 23 45 34 11 1 1 5 19 15 24 15 38 32 4 46 23 11 31 37 48 37 26 17 5 23 16 40 25 36 1 18 34 18 13 4 5 2 43 2 33 20 31 3 12 16 4 19 43 27 6 37 32
output:
169.7531019753
result:
ok found '169.75310', expected '169.75310', error '0.00000'
Test #19:
score: 0
Accepted
time: 17ms
memory: 3940kb
input:
14 16 22 20 42 24 44 28 50 15 12 42 49 34 13 30 25 12 41 8 14 36 24 18 41 51 27 13 19 19 46 51 0 1 2 50 12 20 8 20 17 39 0 41 23 11 11 0 15 43 21 19 45 50 51 42 34 29 18 4 46 14 7 49 39 46 49 1 8 8 6 16 15 31 14 24 43 20 14 51 7 30 35 46 1
output:
191.7225891731
result:
ok found '191.72259', expected '191.72259', error '0.00000'
Test #20:
score: 0
Accepted
time: 16ms
memory: 3756kb
input:
14 47 15 26 51 52 37 36 32 26 48 22 36 6 48 17 31 43 8 2 50 12 4 14 38 3 8 49 30 11 25 27 45 1 3 21 27 47 20 46 2 26 50 50 37 0 23 33 10 30 17 0 1 37 39 28 54 46 38 26 17 23 22 24 49 45 2 1 33 21 1 5 13 28 13 46 49 4 45 30 26 4 35 19 37
output:
189.0083689901
result:
ok found '189.00837', expected '189.00837', error '0.00000'
Test #21:
score: 0
Accepted
time: 17ms
memory: 4052kb
input:
14 43 53 44 6 29 7 42 41 15 2 10 0 12 25 15 0 49 6 29 19 14 21 27 29 10 3 43 25 18 49 4 36 44 48 12 5 23 27 21 38 21 3 38 22 23 48 57 40 36 22 51 32 30 51 43 16 26 33 7 46 25 20 22 37 1 4 22 19 39 56 39 10 39 44 30 6 21 22 13 30 51 25 12 46
output:
184.5144154701
result:
ok found '184.51442', expected '184.51442', error '0.00000'
Test #22:
score: 0
Accepted
time: 17ms
memory: 3800kb
input:
14 58 32 34 36 41 1 37 11 1 27 10 51 32 28 59 33 37 42 60 19 34 5 44 55 42 52 24 19 2 4 52 24 51 9 55 1 53 59 2 50 42 5 32 15 42 5 6 54 1 32 11 58 15 12 18 21 5 12 40 28 44 46 24 5 20 52 49 55 60 27 56 4 22 6 14 48 13 15 7 36 50 15 15 14
output:
212.6891242521
result:
ok found '212.68912', expected '212.68912', error '0.00000'