题目链接: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. java bean转Map

    /** * @author xxxxxxxxxxx * @param object * 待转化类 * @param format自定义转化类型 * @return Map<String,Stri ...

  2. Linux安装java jdk、mysql、tomcat

    安装javajdk 1.8 检查是否安装 rpm -qa | grep jdk rpm方式安装 下载java1.8 jdk http://download.oracle.com/otn-pub/jav ...

  3. javascript中执行环境和作用域(js高程)

    执行环境(execution context,为简单起见,有时也成为“环境”)是javascript中最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了它们各自的行为.每个执行环境 ...

  4. ★Java语法(二)——————————数据类型常见问题

    1.用float型定义变量:float a = 3.14 :是否正确? 不正确.“=” 两边的精度类型不匹配,应为:float a =(float)3.14 或  float a =3.14F 或   ...

  5. Python之function

    1 Function a function is a device that groups a set of statements so they can be run more than once ...

  6. C#判断文件是否存在 //创建txt文件

    if(System.IO.File.Exists(@"")) { } if (System.IO.File.Exists(HttpRuntime.AppDomainAppPath ...

  7. 用批处理实现垃圾文件清除/自动关机/清除copy病毒

    晚上睡觉之前为了下emule经常使用命令shutdown,最近受一个小程序影响想做个自动关机的批处理文件免的麻烦!网上有高手做了个,不过运行时出 现一个绑定错误,at也不能执行,所以后来自己做了简化版 ...

  8. Java基础学习笔记三 正则表达式和校验、Date、DateFormat、Calendar

    正则表达式 正则表达式(英语:Regular Expression,在代码中常简写为regex).正则表达式是一个字符串,使用单个字符串来描述.用来定义匹配规则,匹配一系列符合某个句法规则的字符串.在 ...

  9. ivew使用星星评分

    这组件好像有问题,不知道是我们项目环境造成的还是什么,初始化半星不能正常显示,显示的全星. 1.template <div style="display:inline-block;ma ...

  10. mysql1064问题完美解决

    1.mysql报错code代表具体意思 1005:创建表失败 1006:创建数据库失败 1007:数据库已存在,创建数据库失败 1008:数据库不存在,删除数据库失败 1009:不能删除数据库文件导致 ...