传送门

二维平面四个点求凸包面积->任选三个点面积之和/2

三维平面五个点求凸包体积->任选四个点体积之和/2

二维平面三个点面积->二个二维向量行列式值的绝对值/2

三维平面四个点体积->三个三维向量行列式值的绝对值/6

 //Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define Formylove return 0
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long LL;
typedef double db;
using namespace std; template<typename T>void read(T &x) {
char ch=getchar(); x=; T f=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} struct pt {
db x,y,z;
pt(db x=0.0,db y=0.0,db z=0.0):x(x),y(y),z(z){}
}p[];
pt operator -(const pt&A,const pt&B) { return pt(A.x-B.x,A.y-B.y,A.z-B.z); } db calc(pt p1,pt p2,pt p3,pt p4) {
p1=p1-p4; p2=p2-p4; p3=p3-p4;
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);
return fabs(rs)/6.0;
} int main() {
#ifdef ANS
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
while(scanf("%lf%lf%lf",&p[].x,&p[].y,&p[].z)!=EOF) {
db ans=;
For(i,,) scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
For(i,,) For(j,i+,) For(k,j+,) For(l,k+,)
ans+=calc(p[i],p[j],p[k],p[l]);
ans/=2.0;
printf("%.2lf\n",ans);
}
Formylove;
}
05-27 21:02