HDU 5733 tetrahedron(几何——四面体内心/体积/内切圆)
2016-07-20 14:20
501 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5733
题面:
Total Submission(s): 399 Accepted Submission(s): 153
[align=left]Problem Description[/align]
Given four points ABCD, if ABCD is a tetrahedron, calculate the inscribed sphere of ABCD.
[align=left]Input[/align]
Multiple test cases (test cases
≤100).
Each test cases contains a line of 12 integers [−1e6,1e6]
indicate the coordinates of four vertices of ABCD.
Input ends by EOF.
[align=left]Output[/align]
Print the coordinate of the center of the sphere and the radius, rounded to 4 decimal places.
If there is no such sphere, output "O O O O".
[align=left]Sample Input[/align]
0 0 0 2 0 0 0 0 2 0 2 0
0 0 0 2 0 0 3 0 0 4 0 0
[align=left]Sample Output[/align]
0.4226 0.4226 0.4226 0.4226
O O O O
[align=left]Author[/align]
HIT
[align=left]Source[/align]
2016 Multi-University Training Contest 1
题意:
给定一个四面体,求其内切圆半径和内心,如若不存在输出4个‘O’。
解题:
首先用叉积判断是否四点共面,若四点共面,则不能形成四面体。随后,利用四面体体积公式,海伦公式(求三角形面积),四面体内心公式,求出四面体的内切圆半径和内心。
坑点:
1.输出4个‘O’而不是‘0’。大o怎么长那样,还以为题面给错了....
2.会爆int
引用链接:
求三角形面积——海伦公式
任意四面体体积公式
四面体的内心坐标公式及其应用
代码:
题面:
tetrahedron
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 399 Accepted Submission(s): 153
[align=left]Problem Description[/align]
Given four points ABCD, if ABCD is a tetrahedron, calculate the inscribed sphere of ABCD.
[align=left]Input[/align]
Multiple test cases (test cases
≤100).
Each test cases contains a line of 12 integers [−1e6,1e6]
indicate the coordinates of four vertices of ABCD.
Input ends by EOF.
[align=left]Output[/align]
Print the coordinate of the center of the sphere and the radius, rounded to 4 decimal places.
If there is no such sphere, output "O O O O".
[align=left]Sample Input[/align]
0 0 0 2 0 0 0 0 2 0 2 0
0 0 0 2 0 0 3 0 0 4 0 0
[align=left]Sample Output[/align]
0.4226 0.4226 0.4226 0.4226
O O O O
[align=left]Author[/align]
HIT
[align=left]Source[/align]
2016 Multi-University Training Contest 1
题意:
给定一个四面体,求其内切圆半径和内心,如若不存在输出4个‘O’。
解题:
首先用叉积判断是否四点共面,若四点共面,则不能形成四面体。随后,利用四面体体积公式,海伦公式(求三角形面积),四面体内心公式,求出四面体的内切圆半径和内心。
坑点:
1.输出4个‘O’而不是‘0’。大o怎么长那样,还以为题面给错了....
2.会爆int
引用链接:
求三角形面积——海伦公式
任意四面体体积公式
四面体的内心坐标公式及其应用
代码:
#include <iostream> #include <cstdio> #include <cmath> #include <queue> #include <cstring> #include <string> #include <queue> #include <algorithm> #include <iomanip> #include <vector> #include <set> #include <map> #define eps 1e-8 #define LL long long #define sz1 1000010 #define sz2 100010 #define judge(a,b) (a==0&&b==0)||(a&&b&&(max(a,b)%)) using namespace std; LL x[4],y[4],z[4]; LL a[4],b[4],nx[2],ny[2],nz[2]; double volume,v[6],radius; double s[4],ts; double ax,ay,az; //计算体积 double get_dis(int p,int q) { return sqrt(1.0*(x[p]-x[q])*(x[p]-x[q])+(y[p]-y[q])*(y[p]-y[q])+(z[p]-z[q])*(z[p]-z[q])); } //计算面积 double get_area(int p,int q,int k) { double le[3],ave,res; le[0]=get_dis(p,q); le[1]=get_dis(p,k); le[2]=get_dis(q,k); ave=(le[0]+le[1]+le[2])/2; res=sqrt(ave*(ave-le[0])*(ave-le[1])*(ave-le[2])); return res; } int main() { while(~scanf("%lld",&x[0])) { bool flag=1; scanf("%lld%lld",&y[0],&z[0]); for(int i=1;i<=3;i++) scanf("%lld%lld%lld",&x[i],&y[i],&z[i]); //叉积判断是否四点共面 a[1]=x[1]-x[0];a[2]=y[1]-y[0];a[3]=z[1]-z[0]; b[1]=x[2]-x[1];b[2]=y[2]-y[1];b[3]=z[2]-z[1]; nx[0]=a[2]*b[3]-a[3]*b[2]; ny[0]=a[3]*b[1]-a[1]*b[3]; nz[0]=a[1]*b[2]-a[2]*b[1]; nx[1]=x[3]-x[1];ny[1]=y[3]-y[1];nz[1]=z[3]-z[1]; if(nx[0]*nx[1]+ny[0]*ny[1]+nz[0]*nz[1]==0) printf("O O O O\n"); else { //海伦公式算各面面积 s[0]=get_area(1,2,3); s[1]=get_area(0,2,3); s[2]=get_area(0,1,3); s[3]=get_area(0,1,2); //六条棱棱长平方,其中v[i],v[i+3]为对棱 v[0]=get_dis(0,1); v[1]=get_dis(0,2); v[2]=get_dis(0,3); v[3]=get_dis(2,3); v[4]=get_dis(1,3); v[5]=get_dis(1,2); //套用四面体体积公式 for(int i=0;i<6;i++) v[i]*=v[i]; volume=sqrt(v[0]*v[3]*(v[1]+v[2]+v[4]+v[5]-v[0]-v[3])+v[1]*v[4]*(v[0]+v[2]+v[3]+v[5]-v[1]-v[4])+v[2]*v[5]*(v[0]+v[1]+v[3]+v[4]-v[2]-v[5])-v[0]*v[1]*v[5]-v[1]*v[2]*v[3]-v[2]*v[0]*v[4]-v[3]*v[4]*v[5])/12; radius=volume*3/(s[0]+s[1]+s[2]+s[3]); ax=0; ay=0; az=0; ts=s[0]+s[1]+s[2]+s[3]; //套用四面体内心公式 for(int i=0;i<4;i++) { ax+=s[i]*x[i]; ay+=s[i]*y[i]; az+=s[i]*z[i]; } ax/=ts; ay/=ts; az/=ts; printf("%.4lf %.4lf %.4lf %.4lf\n",ax,ay,az,radius); } } return 0; }
相关文章推荐
- PS制作对称的几何图案
- 总结一下最近做的计算几何学到的知识
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- csu1503 点到圆弧的距离
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000