题目链接: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. BZOJ 4565 状压DP

    思路: f[i][j][S]表示从i到j压成S状态 j-m是k-1的倍数 $f[i][j][S<<1]=max(f[i][j][S<<1],f[i][m-1][S]+f[m][ ...

  2. [SGU 199] Beautiful People

    [SGU 199] Beautiful People The most prestigious sports club in one city has exactly N members. Each ...

  3. Android嵌入式(初稿)--路漫漫其修远兮,吾将上下而求索

  4. set statistics profile on实例

    set statistics profile on实例 1.SQL语句实例   SQL 代码   复制 SET STATISTICS PROFILE ON GO SELECT COUNT(b.[Sal ...

  5. 05-- C++ 类的静态成员详细讲解

     C++ 类的静态成员详细讲解    在C++中,静态成员是属于整个类的而不是某个对象,静态成员变量只存储一份供所有对象共用.所以在所有对象中都可以共享它.使用静态成员变量实现多个对象之间的数据共享不 ...

  6. change project compliance and jre to 1.5

    这个主要检查一下几点 项目的jdk为1.7 java版本设置为1.7 java compiler 的页面设置为以下,并且去掉勾选java compiler 下面的 enableproject spec ...

  7. ssl_protocols和ssl_ciphers应该怎么配置

    http://wiki.nginx.org/HttpSslModule#ssl_ciphers 推荐配置: A) 在Apache 的 SSL 配置中禁用 SSLv3 和 SSLv3SSLProtoco ...

  8. Hotel 旅馆 题解(From luoguBlog)

    考试前深陷分块泥潭所以刚开始以为是分块. 然而这题数据水到暴力卡常都能AC 正解:万物皆可线段树 节点存储区间长度.区间最长连续空房长度.从左往右最长连续空房长度.从右往左最长连续空房长度. 维护后三 ...

  9. 移动APP 微信支付完整过程(wxPay 方案一)

    apicloud.weixinpay官方提供了两种方案. 本模块封装了两套支付方案: 方案一:开发者通过 getOrderId.payOrder 自己处理签名过程(微信开放平台建议把 getOrder ...

  10. Java时间日期格式转换Date转String和String转Date

    Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...