Hdu 4386 Quadrilateral

Quadrilateral

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 890    Accepted Submission(s): 401


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
 

Recommend
zhuyuanchen520

题目意思:给出4条边的边长,若可以组成4边形,则输出能组成的4边形的最大面积,若不能,则输出-1

这个题考查的应该是Bretschneider公式
p=(a+b+c+d)/2 为半周长对于普通四边形,如果其一对内角和为θ,由于四边形的内角和为360度,因此另一对内角和为360-θ

Bretschneider公式,四边形面积S=√[(p-a)(p-b)(p-c)(p-d)-abcdcos^2(θ/2)]

由此我们也可看到,在四边固定的情况下,要使四边形的面积最大,必须使cos^2(θ/2)越小越好,对角和为180度时cos^2(θ/2)=0为最小值。(这意味着两个对角和都为180度)。这样得出的四边形的四个顶点共圆,即属于圆内接四边形。面积最大值就由Brahmagupta公式所得:S=√[(p-a)(p-b)(p-c)(p-d)

因此只知道4条边是不能完全确定这个四边形的,需再测量多一个角度或对角线。

很容易得到只有当4边中最大边的长度小于另外3边长度之和时才能组成4边形,
体现在公式中就是(p-a)*(p-b)*(p-c)*(p-d)需要>0,因为任一边不能大于或等于4条边总长的一半,不然该边就会大于另外3边长度之和;



#include<stdio.h>

#include<math.h>



int main(void)

{

    double a,b,c,d,p,s;

    int T,t;

    scanf("%d",&T);

    for(t=1;t<=T;t++)

    {

        scanf("%lf%lf%lf%lf",&a,&b,&c,&d);

        p=(a+b+c+d)/2;

        s=(p-a)*(p-b)*(p-c)*(p-d);

        if(s>0)

            printf("Case %d: %lf\n",t,sqrt(s));

        else

            printf("Case %d: -1\n",t);

    }

    return 0;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值