hdu 4386Quadrilateral

本文介绍了一道编程题,要求计算由四根给定长度棍子构成的最大面积四边形。利用圆内接四边形特性,通过计算半周长来得出最大面积公式,并提供了解题代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://acm.hdu.edu.cn/showproblem.php?pid=4386

Quadrilateral

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


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
 
四边形不稳定,给定四边后不能确定面积。面积最大的是圆内接四边形,设四边长为abcd,半周长为p,则最大面积=sqrt((p-a)*(p-b)*(p-c)*(p-d))。。忘了怎么证明去了。
View Code
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include<math.h>
 4 int main()
 5 {
 6       int t;
 7       int a,b,c,d,max,count=0;
 8       double p,ans;
 9       scanf("%d",&t);
10       while(t--)
11       {
12             scanf("%d%d%d%d",&a,&b,&c,&d);
13             if(a>b) max=a;
14             else max=b;
15             if(max<b) max=b;
16             if(max<c) max=c;
17             if(max<d) max=d;
18             if(max-(a+b+c+d-max)>=0)
19             {
20                   printf("Case %d: -1\n",++count);
21                   continue;
22             }
23             p=(a+b+c+d)*1.0/2;
24             ans=sqrt((p-a)*(p-b)*(p-c)*(p-d));
25             printf("Case %d: %.6lf\n",++count,ans);
26 
27 
28       }
29 }

 

转载于:https://www.cnblogs.com/1114250779boke/archive/2012/11/09/2763205.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值