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

2012 Multi-University Training Contest 9

题意:

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

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;
}
时间: 2024-12-30 08:24:37

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

Hdu 4386 Play the Dice 解题报告

hdu 4586---Play the dice 解题思路:概率 题目描述:一个骰子有n面,每面朝上的概率相同,并且每一面上面都有一个数字,其中有m面是彩色的,代表掷到彩色面的时还可以继续掷下去,问最终掷得的数字的期望是多少? 解题方法: 方法一:只考虑单独掷每一次的情况,可以发现,每次掷到的期望是和先前无关的,假设a=sum/n(每掷一次的期望都是a),比如:掷第一次的时候期望是a,掷第二次的时候期望便是(m/n)*a,因为有(m/n)的概率能够掷第二次..依次可以继续下去,等比求和即可. u

hdu 4811 Ball(数学)

题目链接:hdu 4811 Ball 题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b.问说给定球的数量后,最大得分为多少. 解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值.那么求峰值就要根据球的数量来决定.我们叫得分为峰值的求为最高得分球,它们有很多个.对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是

HDU 4386

http://acm.hdu.edu.cn/showproblem.php?pid=4386 题意:给四条边长,问能否组成四边形,如果能,求最大面积 求最大面积用海伦公式的四边形推广,p=(a+b+c+d)/2,S=sqrt((p-a)*(p-b)*(p-c)*(p-d)) #include <iostream> #include <cstdio> #include <cstring> #include <map> #include <algorith

hdu 1719 Friend 数学推导

题链:http://acm.hdu.edu.cn/showproblem.php?pid=1719 Friend Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2099    Accepted Submission(s): 1058 Problem Description Friend number are defined recur

hdu 5211 Mutiple 数学

Mutiple Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5211 Description wld有一个序列a[1..n], 对于每个1≤i<n, 他希望你求出一个最小的j(以后用记号F(i)表示),满足i<j≤n, 使aj为ai的倍数(即aj mod ai=0),若不存在这样的j,那么此时令F(i) = 0保证1≤n≤10000,1≤ai≤10000 对于任意

HDU 5047 Sawtooth(数学 公式 大数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 Problem Description Think about a plane: ● One straight line can divide a plane into two regions. ● Two lines can divide a plane into at most four regions. ● Three lines can divide a plane into at m

hdu 5073 Galaxy(数学)

题目链接:hdu 5073 Galaxy 题目大意:给定N个点,可以移动其中的K的点,问说最后I的最小值可以是多少. 解题思路:因为质量都为1嘛,所以就是求方差,可以移动K个,所以即选连续的n=N-K个使得方差最小.注意N=K的情 况. S表示n个数的和,T表示n个数平方的和,那么这n个数的方差即为T - S * S / n,然后扫描一遍数组维护S,T,并且计算 方差的最小值. #include <cstdio> #include <cstring> #include <al

HDU 1030 Delta-wave 数学题解

给出一个数字塔,然后求沿着数字之间的边走,给出两个数字,问其路径最短的长度是多少. 看似一条搜索题目,只是有一定做题经验的人都知道,这个不是搜索题,直接搜索肯定超时. 这个是依据规律计算的数学题目. 我这里的思路是一层一层往下搜,利用层间的规律加速,实现层跃,到了同一层,或者同一个对角列的时候就能够直接计算出结果了.对角列即顺着三角形的边能直接走到目标的列. 数学计算出层与层之间相差2,而也能够利用这个规律计算N和M所在的层和列. 这样做由点麻烦,只是我自己琢磨出来的,不错的思路.O(∩_∩)O

HDU 1099 [Lottery] 数学期望

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1099 题目大意:一套卡片有n张,每次购买随机获得一张卡片,问集齐一套卡片的期望次数是多少? 关键思想:知道此处期望是概率的倒数即可,比如有5张卡片, 第一步你获得想要卡片的概率是1,倒数为1: 第二步你获得想要卡片的概率是4/5,倒数为5/4: 第三步你获得想要卡片的概率是3/5,倒数为5/3: --累加即为结果,格式输出有些坑爹,耐心就好. 代码如下: #include <iostream> u