二维平面四个点求凸包面积->任选三个点面积之和/2
三维平面五个点求凸包体积->任选四个点体积之和/2
二维平面三个点面积->二个二维向量行列式值的绝对值/2
三维平面四个点体积->三个三维向量行列式值的绝对值/6
1 //Achen
2 #include<algorithm>
3 #include<iostream>
4 #include<cstring>
5 #include<cstdlib>
6 #include<vector>
7 #include<cstdio>
8 #include<queue>
9 #include<cmath>
10 #include<set>
11 #include<map>
12 #define Formylove return 0
13 #define For(i,a,b) for(int i=(a);i<=(b);i++)
14 #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
15 typedef long long LL;
16 typedef double db;
17 using namespace std;
18
19 template<typename T>void read(T &x) {
20 char ch=getchar(); x=0; T f=1;
21 while(ch!=‘-‘&&(ch<‘0‘||ch>‘9‘)) ch=getchar();
22 if(ch==‘-‘) f=-1,ch=getchar();
23 for(;ch>=‘0‘&&ch<=‘9‘;ch=getchar()) x=x*10+ch-‘0‘; x*=f;
24 }
25
26 struct pt {
27 db x,y,z;
28 pt(db x=0.0,db y=0.0,db z=0.0):x(x),y(y),z(z){}
29 }p[10];
30 pt operator -(const pt&A,const pt&B) { return pt(A.x-B.x,A.y-B.y,A.z-B.z); }
31
32 db calc(pt p1,pt p2,pt p3,pt p4) {
33 p1=p1-p4; p2=p2-p4; p3=p3-p4;
34 db rs=(p1.x*p2.y*p3.z-p3.x*p2.y*p1.z+p1.y*p2.z*p3.x-p1.x*p2.z*p3.y+p1.z*p2.x*p3.y-p1.y*p2.x*p3.z);
35 return fabs(rs)/6.0;
36 }
37
38 int main() {
39 #ifdef ANS
40 freopen(".in","r",stdin);
41 freopen(".out","w",stdout);
42 #endif
43 while(scanf("%lf%lf%lf",&p[1].x,&p[1].y,&p[1].z)!=EOF) {
44 db ans=0;
45 For(i,2,5) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
46 For(i,1,5) For(j,i+1,5) For(k,j+1,5) For(l,k+1,5)
47 ans+=calc(p[i],p[j],p[k],p[l]);
48 ans/=2.0;
49 printf("%.2lf\n",ans);
50 }
51 Formylove;
52 }
原文:https://www.cnblogs.com/Achenchen/p/9502235.html