HDU 4386(计算几何+婆罗摩笈多公式一般形式)
来源:互联网 发布:知乎周刊pdf 编辑:程序博客网 时间:2024/05/16 15:52
问题描述:
One day the little Jack is playing a game with four crabsticks. The game is simple, he want to make all the four crabsticks to be a quadrilateral, which has the biggest area in all the possible ways. But Jack’s math is so bad, he doesn’t know how to do it, can you help him using your excellent programming skills?
Input
The first line contains an integer N (1 <= N <= 10000) which indicates the number of test cases. The next N lines contain 4 integers a, b, c, d, indicating the length of the crabsticks.(1 <= a, b, c, d <= 1000)
Output
For each test case, please output a line “Case X: Y”. X indicating the number of test cases, and Y indicating the area of the quadrilateral Jack want to make. Accurate to 6 digits after the decimal point. If there is no such quadrilateral, print “-1” instead.
Sample Input
21 1 1 11 2 3 4Sample Output
Case 1: 1.000000Case 2: 4.898979
题目题意:题目给我们四条边长,问可不可以构成四边形,如果可以那么请输出最大的四边形的面积,不行输出-1。
题目分析:四边形存在的充要条件是最大的边长小于其他三边之和。如果存在四边形怎么求四边形的最大面积了。
现在给出四边形面积的一般性结论,对于任意四边形它的面积:
不难发现,我们要四边形的面积最大,即A等于90°,那么此时的四边形是一个圆内接四边形
代码如下:
#include<iostream>#include<cstdio>#include<cmath>#include<cmath>#include<algorithm>using namespace std;int a[4];int main(){ int t,icase=1; scanf("%d",&t); while (t--) { scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]); sort (a,a+4); if (a[3]>=(a[1]+a[2]+a[0])) { printf("Case %d: -1\n",icase++); continue; } else { double s=(double)(a[0]+a[1]+a[2]+a[3])/2.0; double area=sqrt((s-a[0])*(s-a[1])*(s-a[2])*(s-a[3])); printf("Case %d: %.6f\n",icase++,area); } } return 0;}
- HDU 4386(计算几何+婆罗摩笈多公式一般形式)
- 计算几何求公式
- 计算几何相关公式
- 计算几何公式
- 计算几何公式总结
- hdu 5448 Marisa’s Cake(计算几何加推公式)
- HDU 5531 几何公式
- [计算几何]几何图形及计算公式查询
- hdu 3952 计算几何
- HDU 3694计算几何
- hdu 4195#计算几何
- hdu 4353 计算几何
- hdu 3681 计算几何
- hdu 3629 计算几何
- hdu 3629 计算几何
- hdu 5476 (计算几何)
- hdu 2826 计算几何
- hdu 1007(计算几何)
- RAC数据恢复到单节点
- 数据报警系统
- LightOJ
- 《珠珠图案》教程五:文字创作要领二
- flock和fcntl的区别
- HDU 4386(计算几何+婆罗摩笈多公式一般形式)
- HttpURLConnection,OKHttp以及xml解析
- 超级快印自助复印点位链接
- DevOps落地实践:BAT系列:ALI:企业研发效能解决方案
- 十道海量数据处理面试题与十个方法大总结
- android-----------实现微信登录和分享功能。
- Python的pickle模块
- android 打印线程信息
- linux系统安装redis教程