zoukankan      html  css  js  c++  java
  • [模板]三维凸包(无讲解)

     1 // luogu-judger-enable-o2
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 typedef long double ld;
     5 const int maxn=2E3+5;
     6 const ld eps=1E-9;
     7 int n;
     8 bool vis[maxn][maxn];
     9 struct pt
    10 {
    11     ld x,y,z;
    12     pt(ld a=0,ld b=0,ld c=0):x(a),y(b),z(c){}
    13     pt operator+(const pt&A){return pt(x+A.x,y+A.y,z+A.z);}
    14     pt operator-(const pt&A){return pt(x-A.x,y-A.y,z-A.z);}
    15     pt operator*(const pt&A){return pt(y*A.z-z*A.y,z*A.x-x*A.z,x*A.y-y*A.x);}
    16     ld operator&(const pt&A){return x*A.x+y*A.y+z*A.z;}
    17     ld len(){return sqrt(x*x+y*y+z*z);}
    18 }a[maxn];
    19 struct face
    20 {
    21     int v[3];
    22     pt normal(){return (a[v[1]]-a[v[0]])*(a[v[2]]-a[v[0]]);}
    23     ld area(){return normal().len()/2;}
    24 }f[maxn],wait[maxn];
    25 int cnt;
    26 inline int see(face A,pt B)
    27 {
    28     return ((B-a[A.v[0]])&A.normal())>0;
    29 }
    30 void solve()
    31 {
    32     f[++cnt]=(face){1,2,3};
    33     f[++cnt]=(face){3,2,1};
    34     for(int i=4;i<=n;++i)
    35     {
    36         int tot=0;
    37         for(int j=1;j<=cnt;++j)
    38         {
    39             if(!see(f[j],a[i]))
    40             {
    41                 wait[++tot]=f[j];
    42                 for(int k=0;k<3;++k)
    43                     vis[f[j].v[k]][f[j].v[(k+1)%3]]=0;
    44             }
    45             else
    46             {
    47                 for(int k=0;k<3;++k)
    48                     vis[f[j].v[k]][f[j].v[(k+1)%3]]=1;
    49             }
    50         }
    51         for(int j=1;j<=cnt;++j)
    52             for(int k=0;k<3;++k)
    53             {
    54                 int x=f[j].v[k],y=f[j].v[(k+1)%3];
    55                 if(vis[x][y]&&(!vis[y][x]))
    56                     wait[++tot]=(face){x,y,i};
    57             }
    58         for(int j=1;j<=tot;++j)
    59             f[j]=wait[j];
    60         cnt=tot;
    61     }
    62 }
    63 int main()
    64 {
    65     ios::sync_with_stdio(false);
    66     cin>>n;
    67     for(int i=1;i<=n;++i)
    68         cin>>a[i].x>>a[i].y>>a[i].z;
    69     solve();
    70     ld ans=0;
    71     for(int i=1;i<=cnt;++i)
    72         ans+=f[i].normal().len()/2;
    73     cout<<fixed<<setprecision(3)<<ans<<endl;
    74     return 0;
    75 }
    View Code
  • 相关阅读:
    (轻松一刻)神秘而又强大的蓝翔学院!而且还是当中最可怕的挖掘机系!
    IIS 反向代理二级目录及泛目录
    正则表达式匹配外链和内链
    关于 preg_replace_callbank 的学习记录
    Linux 笔记
    Linux 笔记
    Linux 笔记
    使用 Docker 安装 showdoc
    Docker 入门
    Linux 笔记
  • 原文地址:https://www.cnblogs.com/GreenDuck/p/11516664.html
Copyright © 2011-2022 走看看