QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#347295 | #6752. Geometry | wtz2333 | AC ✓ | 24ms | 4076kb | C++17 | 5.0kb | 2024-03-09 13:01:50 | 2024-03-09 13:01:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr double eps = 1e-7;
constexpr double PI = acos(-1);
constexpr double inf = 1e9;
struct Point { double x, y; }; // 点
using Vec = Point; // 向量
struct Line { Point P; Vec v; }; // 直线(点向式),射线时为A->B
struct Seg { Point A, B; }; // 线段(存两个端点)
struct Circle { Point O; double r; }; // 圆(存圆心和半径)
using Points = std::vector<Point>;
using ConvexHull = std::vector<Point>;
const Point O = {0, 0}; // 原点
const Line Ox = {O, {1, 0}}, Oy = {O, {0, 1}}; // 坐标轴
bool eq(double a, double b) { return abs(a - b) < eps; } // ==
bool gt(double a, double b) { return a - b > eps; } // >
bool lt(double a, double b) { return a - b < -eps; } // <
bool ge(double a, double b) { return a - b > -eps; } // >=
bool le(double a, double b) { return a - b < eps; } // <=
Vec operator + (const Vec &a,const Vec &b){return (Vec){a.x + b.x,a.y + b.y};}
Vec operator - (const Vec &a,const Vec &b){return (Vec){a.x - b.x,a.y - b.y};}
Vec operator * (const Vec &a,const double &b){return (Vec){b * a.x,b * a.y};}
Vec operator * (const double &a,const Vec &b){return (Vec){a * b.x,a * b.y};}
Vec operator / (const Vec &a,const double &b){return (Vec){a.x / b,a.y / b};}
double operator * (const Point &a,const Point &b){return a.x * b.x + a.y * b.y;}// dot // 点乘
double operator ^ (const Point &a,const Point &b){return a.x * b.y - a.y * b.x;}// cross // 叉乘
bool operator < (const Point& a, const Point& b) {return a.x < b.x || (a.x == b.x && a.y < b.y);}
double len(Vec a){return sqrt(a * a);}
ll cross(Point a,Point b){return (ll)a.x * (ll)b.y - (ll)a.y * (ll)b.x;}
ll dot(Point a,Point b){return (ll)a.x * (ll)b.x + (ll)a.y * (ll)b.y;}
// Graham扫描法
// DEPENDS eq, lt, cross, V-V, P<P
// double theta(Point p) { return p == O ? -1 / 0. : atan2(p.y, p.x); } // 求极角
// void psort(Points &ps, Point c = O) { // 极角排序
// sort(ps.begin(), ps.end(), [&](auto a, auto b) {
// return lt(theta(a - c), theta(b - c));
// });
// }
/*
//极角排序
int qua(const Point &P){
if(P.x == 0 && P.y == 0) return 0;
if(P.x >= 0 && P.y >= 0) return 1;
if(P.x < 0&& P.y >= 0) return 2;
if(P.x<0 && P.y < 0) return 3;
if(P.x >= 0 && P.y < 0) return 4;
exit(-1);
}
void psort(Points &ps, Point c = O){ // 极角排序
stable_sort(ps.begin(), ps.end(), [&](auto p1, auto p2) {
return qua(p1 - c) < qua(p2 - c) || qua(p1 - c) == qua(p2 - c) && gt((Point)(p1 - c) ^ (Point)(p2 - c), 0);
});
}
// 检查向量夹角acb小于180
bool check1(Point a,Point b,Point c){//
ll d = (a - c) ^ (b - c);
if(d > 0)return true;
if(d < 0)return false;
return (a - c) * (b - c) > 0;
}
*/
bool check(Point p, Point q, Point r){ // 检查三个点组成的两个向量的旋转方向是否为逆时针
return lt(0, (q - p) ^ (r - q));
}
ConvexHull Andrew(Points &ps){
if(ps.size() == 1){
return ps;
}
sort(ps.begin(), ps.end());
std::vector<int> I{0}, used(ps.size());
for (int i = 1; i < ps.size(); i++){
//std::cout << ps[i].x << " " <<ps[i].y <<"\n";
while (I.size() > 1 && !check(ps[I[I.size() - 2]], ps[I.back()], ps[i]))
used[I.back()] = 0, I.pop_back();
used[i] = 1, I.push_back(i);
}
int tmp = I.size();
for (int i = ps.size() - 2; i >= 0; i--){
if (used[i])
continue;
while (I.size() > tmp && !check(ps[I[I.size() - 2]], ps[I.back()], ps[i]))
used[I.back()] = 0, I.pop_back();
used[i] = 1, I.push_back(i);
}
Points H;
for (int i = 0; i < I.size() - 1; i++)
H.push_back(ps[I[i]]);
return H;
}//逆时针
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<array<Point,3>> a(n);
for(int i = 0;i < n;i ++) {
for(int j = 0;j < 3;j ++) {
cin >> a[i][j].x >> a[i][j].y;
}
}
int N = (1 << n);
vector<double> f(N),dp(N,1e9);
auto calc = [&](Points &a) -> double{
double ans = 0;
int n = a.size();
for(int i = 0;i < n;i ++) {
ans += len(a[(i + 1) % n] - a[i]);
}
return ans;
};
for(int i = 1;i < N;i ++) {
vector<Point> b;
for(int j = 0;j < n;j ++) {
if(i & (1 << j)) {
for(int k = 0;k < 3;k ++) b.push_back(a[j][k]);
}
}
auto C = Andrew(b);
f[i] = calc(C);
// cerr << fixed << setprecision(10) << f[i] << "\n";
}
dp[0] = 0;
for(int s = 1;s < N;s ++) {
for(int i = s; i; i = (i - 1) & s) {
dp[s] = min(dp[s],dp[i ^ s] + f[i]);
}
}
cout << fixed << setprecision(10) << dp[N - 1] << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3964kb
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: 1ms
memory: 3900kb
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: 21ms
memory: 3944kb
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: 22ms
memory: 3944kb
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: 22ms
memory: 3852kb
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: 23ms
memory: 3844kb
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: 23ms
memory: 4012kb
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: 23ms
memory: 3912kb
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: 23ms
memory: 3792kb
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: 24ms
memory: 3988kb
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: 23ms
memory: 4016kb
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: 3796kb
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: 23ms
memory: 3852kb
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: 23ms
memory: 3792kb
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: 23ms
memory: 4072kb
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: 24ms
memory: 4076kb
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: 23ms
memory: 4076kb
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: 23ms
memory: 3848kb
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: 19ms
memory: 3908kb
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: 22ms
memory: 3792kb
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: 23ms
memory: 3912kb
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: 22ms
memory: 3872kb
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'