QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196518#7521. Find the Gapucup-team139TL 1ms3924kbC++233.6kb2023-10-01 18:33:542023-10-01 18:33:55

Judging History

你现在查看的是最新测评结果

  • [2023-10-01 18:33:55]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3924kb
  • [2023-10-01 18:33:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using T = long long;
struct p3 {
    T x,y,z;
    p3 operator+(p3 p) {return {x+p.x, y+p.y, z+p.z};}
    p3 operator-(p3 p) {return {x-p.x, y-p.y, z-p.z};}
    p3 operator*(T d) {return {x*d, y*d, z*d};}
    p3 operator/(T d) {return {x/d, y/d, z/d};}
    bool operator==(p3 p) {
        return tie(x,y,z) == tie(p.x,p.y,p.z);
    }
    bool operator!=(p3 p) {return !operator==(p);}
};
T operator|(p3 v, p3 w) { // dot product
    return v.x*w.x + v.y*w.y + v.z*w.z;
}
p3 operator*(p3 v, p3 w) { // cross product
    return {v.y*w.z - v.z*w.y,
        v.z*w.x - v.x*w.z,
        v.x*w.y - v.y*w.x};
}
T norm(p3 v) {return v|v;} //modulo^2
long double abs(p3 v) {return sqrtl(norm(v));} //modulo
p3 unit(p3 v) {return v/abs(v);} //versore ($|v|\neq 0$)

//>0 sse s è sopra il piano pqr, nella direzione di $\overrightarrow{PQ}\times\overrightarrow{PR}$
T orient(p3 p, p3 q, p3 r, p3 s) {
    return (q-p) * (r-p) | (s-p); //0 sse p,q,r,s coplanari
}
// orientamento 2D delle proiezioni di p, q, r
// rispetto al piano perpendicolare a n
T orientByNormal(p3 p, p3 q, p3 r, p3 n) {
    return (q-p) * (r-p) | n;
}
struct plane {
    p3 n; T d;
    // From normal n and offset d
    plane(p3 n, T d) : n(n), d(d) {}
    // From normal n and point P
    plane(p3 n, p3 p) : n(n), d(n|p) {}
    // From three non-collinear points P,Q,R
    plane(p3 p, p3 q, p3 r) : plane((q-p)*(r-p), p) {}
    T side(p3 p) {return (n|p)-d;}
    long double dist(p3 p) {return ((long double)(abs(side(p))))/abs(n);}
    plane translate(p3 t) {return {n, d+(n|t)};}
    // requires double
    plane shiftUp(T dist) {return {n, d+dist*abs(n)};}
    p3 proj(p3 p) {return p - n*side(p)/norm(n);}
    p3 refl(p3 p) {return p - n*2*side(p)/norm(n);}
};

const int MAXN = 55;
int n;
p3 v[MAXN];

bool all(p3 a,p3 b,p3 c){
    return (b-a)*(c-a)==p3(0,0,0);
}

bool check(plane p1,plane p2){
    
    for(int i=0;i<n;i++){
        if(p1.side(v[i])>0 && p2.side(v[i])>0)return false;
        if(p1.side(v[i])<0 && p2.side(v[i])<0)return false;
    }
    
    return true;
}

void solve(){
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>v[i].x>>v[i].y>>v[i].z;
    }
    
    bool ok=true;
    for(int i=0;i+2<n;i++){
        if(!all(v[i],v[i+1],v[i+2]))ok=false;
    }
    
    if(ok){
        cout<<"0.0\n";
        return;
    }
    
    long double ans=2e5;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                for(int l=0;l<n;l++){
                    if(i==j || i==k || i==l || j==k || j==l || k==l)continue;
                    
                    auto a=v[i],b=v[j],c=v[k],d=v[l];
                    
                    if(!all(a,b,c)){
                        plane pl1(a,b,c);
                        plane pl2 = pl1.translate(d-a);

                        if(check(pl1,pl2)){
                            ans=min(ans,pl1.dist(d));
                        }
                    }
                    
                    if(!all(a,b,b+(d-c))){
                        plane pl1(a,b,b+(d-c));
                        plane pl2 = pl1.translate(d-a);
                        
                        if(check(pl1,pl2)){
                            ans=min(ans,pl1.dist(d));
                        }
                    }
                }
            }
        }
    }
    
    cout<<setprecision(20)<<ans<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++)solve();
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3924kb

input:

8
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

output:

1

result:

ok found '1.000000000', expected '1.000000000', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

5
1 1 1
1 2 1
1 1 2
1 2 2
2 1 1

output:

0.70710678118654752444

result:

ok found '0.707106781', expected '0.707106781', error '0.000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

50
973 1799 4431
1036 1888 4509
1099 1977 4587
1162 2066 4665
1225 2155 4743
1288 2244 4821
1351 2333 4899
1414 2422 4977
1540 2600 5133
1603 2689 5211
1666 2778 5289
1729 2867 5367
1792 2956 5445
1855 3045 5523
1918 3134 5601
1981 3223 5679
2044 3312 5757
2107 3401 5835
2170 3490 5913
2296 3668 606...

output:

0.0

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

50
4532 3245 1339
4624 3260 1345
4716 3275 1351
4808 3290 1357
4900 3305 1363
5084 3335 1375
5176 3350 1381
5268 3365 1387
5360 3380 1393
5452 3395 1399
5544 3410 1405
5728 3440 1417
5820 3455 1423
5912 3470 1429
6096 3500 1441
6188 3515 1447
6280 3530 1453
6372 3545 1459
6464 3560 1465
6556 3575 14...

output:

0.0

result:

ok found '0.000000000', expected '0.000000000', error '-0.000000000'

Test #5:

score: -100
Time Limit Exceeded

input:

50
1 70 7443
1 138 5063
2 109 5971
3 23 8874
3 152 4359
4 59 7507
5 50 7715
5 73 6910
7 25 8376
7 103 5646
8 3 9039
9 83 6132
9 142 4067
10 124 4590
11 140 3923
12 168 2836
13 46 6999
13 84 5669
13 189 1994
13 229 594
15 171 2410
16 94 4998
20 38 6530
20 125 3485
21 78 5023
22 210 296
23 117 3444
25...

output:


result: