Contest - 2013校赛暨华中邀请赛 Problem D: Tetrahedron Inequality
来源:互联网 发布:淘宝店铺首页视频代码 编辑:程序博客网 时间:2024/06/05 09:00
Problem D: Tetrahedron Inequality
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 14 Solved: 2
[Submit][Status][Web Board]
Problem D: Tetrahedron Inequality
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 14 Solved: 2
[Submit][Status][Web Board]
Description
It is well known that you cannot make a triangle with non-zero area whose sides have lengths 1, 2, 3. Can you make a tetrahedron(四面体) with non-zero volume whose edges have lengths 1, 2, 3, 4, 5, 6?
Input
The first line of input contains an integer 0 < n <= 10000, the number of lines to follow. Each of the next n lines contains six positive integers separated by spaces, the lengths of the edges of the desired tetrahedron. The length of each edge is no greater than 1000000.
Output
Output n lines, each containing the word YES if it is possible to construct a tetrahedron with non-zero volume with the given edge lengths, or the word NO if it is not possible.
Sample Input
21 2 3 4 5 610 10 10 10 10 18
Sample Output
NONO
题意:输入六个数让你判断他们能否组成四面体。上次去抵达比赛没做出来的,当时想的太简单了,一直WA,比赛结束后才知道为什么
,是任选五条边的各种三角形的组合没考虑。今天又做了一下,很快写好了,可是想AC还是不容易啊,具体的看注释吧/**************************************************************
Problem: 1432
User: wust_*******
Language: C
Result: Accepted
Time:44 ms
Memory:760 kb
****************************************************************/
#include<stdio.h> #include<math.h> int judge(double a,double b,double c) { if(a+b>c&&a+c>b&&b+c>a) //能否组成三角形 return 1; else return 0; } int cal(double a,double b,double c,double d,double e,double f) { if(a>1000) //因为题目说明了边的范围<=1000000,如果输入1000000的边长,看看后面的带乘法的运算每一个都能爆掉,这就是刚才WA好多的原因,所以对大数据要同时除以1000.0
{ a/=1000.0; b/=1000.0; c/=1000.0; d/=1000.0; e/=1000.0; f/=1000.0; } double L1,L2,h1,h2,x1,x2,ff; L1=(a+b+d)/2.0; L2=(a+c+e)/2.0; h1=2*sqrt(L1)*sqrt(L1-a)/a*sqrt(L1-b)*sqrt(L1-d);// 算高的 h2=2*sqrt(L2)*sqrt(L2-a)/a*sqrt(L2-c)*sqrt(L2-e); x1=(b*b+e*e-d*d-c*c)/4/a/a*(b*b+e*e-d*d-c*c);//两个三角形高之间的距离平方 ff=f*f; if(ff<(h1+h2)*(h1+h2)+x1&&ff>(h1-h2)*(h1-h2)+x1) //根据任意可以组成两个三角形的五条边来算第六条边f的长度范围,看f是否在这个范围内 return 1; else return 0; } int main() { int t,a,b,c,d,e,f,i,j; double r[6]; scanf("%d",&t); while(t--) { for(i=0;i<6;i++) scanf("%lf",&r[i]); for(j=0,a=0;a<5;a++) { for(b=0;b<5;b++) { if(a!=b) for(c=0;c<5;c++) { if(a!=c&&b!=c) //保证不会选重边 for(d=0;d<5;d++) { if(a!=d&&d!=c&&b!=d&&judge(r[a],r[b],r[d])) for(e=0;e<5;e++) { if(a!=e&&d!=e&&b!=e&&c!=e) if(judge(r[a],r[c],r[e])) { if(cal(r[a],r[b],r[c],r[d],r[e],r[5])) //计算能否组成四面体 { j++; break; //有一个成立就退出循环 } } if(j) break; } if(j) break; } if(j) break; } if(j) break; } if(j) break; } if(j) printf("YES\n"); else printf("NO\n"); } return 0; }
- Contest - 2013校赛暨华中邀请赛 Problem D: Tetrahedron Inequality
- Contest - Problem D
- codeforces contest/796/problem/D
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 Problem 1603 - Minimum Sum
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 Problem 1608 - Calculation
- 武汉大学 华中区邀请赛总结
- 华中15邀请赛网络赛
- 2016武汉大学华中邀请赛总结
- 2013 Asia Reginal Contest Problem D --- Chocolate (DP + 二分)
- 第四届华中区程序设计邀请赛暨武汉大学第十三届校赛 网络预选赛 Problem 1566 - C - Spanning Tree
- 2012 JinHuaSite Regional Contest Problem D
- http://codeforces.com/contest/263/problem/D
- http://codeforces.com/contest/366/problem/D
- http://codeforces.com/contest/368/problem/D
- http://codeforces.com/contest/432/problem/D
- codeforces contest 868 problem D(玄学)
- 2012金华邀请赛 Problem D. Garden 线段树题目
- 首届华中区程序设计邀请赛 总结
- 为什么要对url进行encode
- CGAL库
- 模式匹配的几种算法(含KMP算法)
- hdu 1698
- AP Invoice创建会计科目脚本
- Contest - 2013校赛暨华中邀请赛 Problem D: Tetrahedron Inequality
- POJ 1195 Open the Lock
- 博弈入门必备知识&&入门题 hdu1846 HDU1847 HDU1527 hdu2516 HDU1849 HDU1848 HDU1907
- 计算日期
- eclisp汉化教程
- 指针的低级错误!铭记!
- 现在编程语言还重要吗?
- Android代码累积
- 7.windbg script - 显示所有模块文件头