田益铭

我们一直在向前走,不是吗? 你必须非常努力,才能看起来毫不费力。

HDU 4386 Quadrilateral(数学)

题目链接: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;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。vasttian https://blog.csdn.net/u012860063/article/details/46816091
文章标签: 数学 HDU
个人分类: 数学篇
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

HDU 4386 Quadrilateral(数学)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭