hdu Quadrilateral(多校)

Quadrilateral

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
 AC代码:

#include <stdio.h>
#include <math.h>
int a[45];
int main( )
{
int i,j;
int tests;
int cases=0;
scanf("%d",&tests);
while(tests--)
{
int maxn=0,index;
int s=0;
for( i=1;i<=4;i++)
{
scanf("%d",&a[i]);
if(maxn<a[i]) { maxn=a[i];index=i;}
}
for( i=1;i<=4;i++)
{
if(i!=index)
s+=a[i];
}
printf("Case %d: ",++cases);

//判断是否构成四边形
if(s>maxn)
{
double z=(s+maxn)/(2.0);//求面积
double sum=sqrt((z-a[1])*(z-a[2])*(z-a[3])*(z-a[4]));
printf("%.6lf\n",sum);
}
else
printf("-1\n");

}
return 0;
}

posted @ 2012-08-21 14:07  jiai  Views(192)  Comments(0Edit  收藏  举报