题目链接: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. Android Studio Library 编译成 jar,aar

    1. 导入Library ,打开Library 的build gradle  在最外面添加如下: /** AVLView 自定义的jar 包名 **/ task clearJar(type: Dele ...

  2. 错误:android.view.InflateException: Binary XML file line #167: Binary XML file line #167: Error inflating class <unknown>

    1:错误日志 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.8.activity.RecordActiv ...

  3. 【PostgreSQL-9.6.3】函数(3)--日期和时间函数

    在PostgreSQL中,DATE.TIME.TIMESTAMP是三种不同的数据类型.DATE表示日期类型,格式为YYYY-MM-DD或YYYYMMDD:TIME表示时间类型,格式为hh:mi:ss: ...

  4. MyEclipse 连接Oracle数据库(初学者必看)

    前言:刚接触Oracle数据库,便有一个需求,编写控制台程序,实现主人登录.数据库为Oracle.下面详细介绍一下MyEclipse 连接Oracle数据库.   package DbHelp; im ...

  5. numpy安装失败-小失误

    1. 古老的方法:            安装python numpy库AMD64 失败,网上的教程是这样的:http://www.cnblogs.com/zhuyp1015/archive/2012 ...

  6. Lazarus开发环境编译选项配置

    Lazarus的环境配置让人有点犯晕,对于刚从delphi转到lazarus上的我来说,每次新建工程都会遇到一堆Can't find unit xxxx used by xxxx的问题,问题虽然不大, ...

  7. Android进度条控件ProgressBar使用

    ProgressBar有四种样式,圆形的(大,中,小)和直条形的(水平) 对应的style为 <LinearLayout xmlns:android="http://schemas.a ...

  8. jquery-pjax

    项目介绍: Pjax是jQuery的一个插件,Pjax即pushState + Ajax,是实现无刷新Ajax加载并解决浏览器前进和后退问题的一个开源实现. 在2012年8月28日发布0.9版本. P ...

  9. nginx_安装测试

    首先安装环境: [root@local nginx-1.9.14]#  yum install gcc-c++  pcre pcre-devel  zlib zlib-devel openssl op ...

  10. 使用.Net Core RT 标准动态库

    这个文档可以引导你如何通过CoreRT生成一个原生标准的系统动态库让其他编程语言调用. CoreRT 可以构建静态库, 这些库可以在编译时链接或者也可以构建运行时所需的共享库, 创建一个支持CoreR ...