题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4386

Problem Description
  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
2
1 1 1 1
1 2 3 4
 
Sample Output
Case 1: 1.000000
Case 2: 4.898979
 
Author
WHU
 
Source

题意:

给出四条边的长度,求是否能形成四边形。假设能形成求最大面积。

PS:

四边形最大面积:

L = (A+B+C+D)/2;

AREA = sqrt((L-A) * (L-B)*(L-C)*(L-D));

代码例如以下:

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int t;
int cas = 0;
scanf("%d",&t);
while(t--)
{
int a[4];
for(int i = 0; i < 4; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+4);
int sum = a[0]+a[1]+a[2];
if(sum <= a[3])
{
printf("Case %d: -1\n",++cas);
continue;
}
double p = (a[0]+a[1]+a[2]+a[3])/2.0;
double area = sqrt((p-a[0])*(p-a[1])*(p-a[2])*(p-a[3]));
printf("Case %d: %.6lf\n",++cas,area); }
return 0;
}

HDU 4386 Quadrilateral(数学啊)的更多相关文章

  1. HDU 4386 Quadrilateral(四边形的海伦公式的应用)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115760#problem/G 题目大意是给出四条边,问能否组成一个四边形,如果 ...

  2. HDU 4386

    http://acm.hdu.edu.cn/showproblem.php?pid=4386 题意:给四条边长,问能否组成四边形,如果能,求最大面积 求最大面积用海伦公式的四边形推广,p=(a+b+c ...

  3. HDU 5673 Robot 数学

    Robot 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 Description There is a robot on the origi ...

  4. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  5. HDU 2493 Timer 数学(二分+积分)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493 题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来 ...

  6. HDU 1568 Fibonacci 数学= = 开篇

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1568 分析:一道数学题 找出斐波那契数列的通项公式,再利用对数的性质就可得到前几位的数 斐波那契通项公 ...

  7. hdu 4602 Partition 数学(组合-隔板法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4602 我们可以特判出n<= k的情况. 对于1<= k<n,我们可以等效为n个点排成 ...

  8. HDU 1030 Delta-wave 数学题解

    给出一个数字塔,然后求沿着数字之间的边走,给出两个数字,问其路径最短的长度是多少. 看似一条搜索题目,只是有一定做题经验的人都知道,这个不是搜索题,直接搜索肯定超时. 这个是依据规律计算的数学题目. ...

  9. HDU 5698 瞬间移动 数学

    瞬间移动 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5698 Description 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次 ...

随机推荐

  1. springboot 的一般配置

    import javax.servlet.Filter; import org.springframework.boot.SpringApplication; import org.springfra ...

  2. yaml标记语言的简介

    今天遇到yml这个文件,挺懵的.也是百度了一把. 这篇博文不错:http://www.ibm.com/developerworks/cn/xml/x-1103linrr/ 这图画得不错:http:// ...

  3. jQuery学习笔记之DOM操作、事件绑定(2)

    jQuery学习笔记之DOM操作.事件绑定(2) --------------------学习目录------------------------ 4.DOM操作 5.事件绑定 源码地址: https ...

  4. VmWare 安装 Centos

    VMware CentOS7 的 ISO 文件 方法/步骤   1 打开虚拟机软件“VMware”,选择“创建新的虚拟机”: 2 选择“自定义(高级)”选项,点击“下一步”: 3 在“硬件兼容性”处选 ...

  5. 【Android】实例 忐忑的精灵

    在Android Studio中创建项目,名称为“Animation And Multimedia”,然后在该项目中创建一个Module,名称为“Frame-By-Frame Animation”.在 ...

  6. windows下查看端口进程占用情况

    引用:http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html 我们在启动应用的时候经常发现我们需要使用的端口被别的程序占用,但是我 ...

  7. Windows-Server-2008、IIS7.0环境下配置伪静态化

    在Windows-Server-2008.IIS7.0环境下配置伪静态化                首先,是IIS7.0的配置,由于Windows Server 2008操作系统默认的IIS版本为 ...

  8. CNN结构:SPP-Net为CNNs添加空间尺度卷积-神经元层

    前几个CNN检测的框架要求网络的图像输入为固定长宽,而SPP-Net在CNN结构中添加了一个实现图像金字塔功能的卷积层SPP层,用于在网络中实现多尺度卷积,由此对应多尺度输入,以此应对图像的缩放变换和 ...

  9. MFC 缩放和显示IplImage

    序言:使用OpenCV嵌入MFC的框内,图像大小不能和框大小进行匹配,因此需要缩放,使图像适用于MFC框. 后来找到了一种新的方法,此方案貌似u已经废弃. (1).在MFC中显示图片 void CAv ...

  10. 创建一个类Person

    创建一个类Person,包含以下属性:姓名(name).年龄(age).朋友(friends数组).问候(sayhi方法,输出问候语,例如:"你好!").交朋友(addFriend ...