码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4386

时间:2014-11-27 10:28:21      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

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))

bubuko.com,布布扣
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stack>
#include <set>

using namespace std;

int main(){
    int T;
    scanf("%d",&T);
    for(int cas=1;cas<=T;cas++){
        int a[4];
        for(int i=0;i<4;i++)
            scanf("%d",&a[i]);
        sort(a,a+4);
        printf("Case %d: ",cas);
        if(a[3]<(a[0]+a[1]+a[2])){
            double p=(a[0]+a[1]+a[2]+a[3])/2.0;
            printf("%.6lf\n",sqrt((p-a[0])*(p-a[1])*(p-a[2])*(p-a[3])));
        }
        else puts("-1");
    }
    return 0;
}
View Code

 

HDU 4386

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/xiaohongmao/p/4125605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!