题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4386
简单几何。
四边形面积,直接套公式就OK。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
double s[4];
double area(double a,double b,double c,double d){
if(a+b+c<=d || a+b+d<=c || a+c+d<=b || c+b+d<=a) return -1;
double ss=(a+b+c+d)/2;
return sqrt((ss-a)*(ss-b)*(ss-c)*(ss-d));
}
int main(){
int t,tt=1,i;
double res,tmp;
scanf("%d",&t);
while(t--){
for(i=0;i<4;i++)
scanf("%lf",&s[i]);
res=area(s[0],s[1],s[2],s[3]);
printf("Case %d: ",tt++);
if(res<=0) puts("-1");
else printf("%.6lf\n",res);
}
return 0;
}