ZOJ Monthly, January 2014 F The Three Guys (浙江大学月赛)

来源:互联网 发布:淘宝直播开通步骤 编辑:程序博客网 时间:2024/05/21 22:26

The Three Guys

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

Recent days, a joke spread out among Chinese social networks. "If Yao Ming,Guo Jingming and He Jiong lying on the ground, can they form a triangle?"

Some netizens think that it is impossible to form a triangle since Yao Ming is a basketball giant, whileGuo Jingming and He Jiong are artists with short statures.

But another group of netizens came out and claim: "Yes, they can!" Someone even has presented a sketch to prove their theory:

HowToFormTriangles.jpg

There are three guys in somewhere of the world. They have learned of this idea and want to try it out by themselves. Given you the height of the three guys, please find out the maximum area of triangle they can form. The height consists of two parts: the upper part of body Ui and the lower part of body Li.

Input

There are multiple test cases (about 3000). For each test case:

There are three lines. Each line consists of two integers Ui andLi (1 <= Ui, Li <= 150) indicates the height of two parts of thei-th guy.

Output

For each test case, output the maximum area of triangle they can form. Any solution with a relative or absolute error of at most 1e-9 will be accepted.

Sample Input

10 1020 2030 30

Sample Output

600.000000000000

Author: JIANG, Kai
Source: ZOJ Monthly, January 2014
Submit   Status

对于这道题又在黑郭敬明等人。我表示很无聊。。但是这是题目还是要做的

题意:给出三个人的上半身和下半身身高。让你利用他们组成的三角形面积最大。(ps每个人是可以折叠的)

题解:对于每个人可以折叠这样组合还是有很多种的,如果就用if来判断这可是太容易出错了。

所以我用DFS递归每一种情况。对于递归,可以先把他们首尾相接连成一条圆。然后在圆中选择三个点作为角,这就是一种情况的三角形了

#include<cstdio>#include<cstring>#include<math.h>double len[5][5];double a[10];double fr,se,th;double ans;double sum[10];int vi[10];double Max(double a,double b){return a>b?a:b;}double area(double a,double b,double c){double s = (a+b+c)/2.0;double v = s*(s-a)*(s-b)*(s-c);if(v>0.0)v = sqrt(v);else v = 0;return v;}void DFS(){int i,j,k;for(i=0;i<4;i++)for(j=i+1;j<5;j++)for(k=j+1;k<6;k++){ans = Max(ans,area(sum[i]+sum[5]-sum[k],sum[j]-sum[i],sum[k]-sum[j]));}}void work(int b,int s){int i;if(s==3){sum[0] = a[0];for(i=1;i<6;i++)sum[i] = sum[i-1]+a[i];DFS();return ;}for(i=0;i<3;i++){if(!vi[i]){vi[i] = 1;a[b] = len[i][0];a[b+1] = len[i][1];work(b+2,s+1);a[b] = len[i][1];a[b+1] = len[i][0];work(b+2,s+1);vi[i] = 0;}}}int main(){while(~scanf("%lf%lf",&len[0][0],&len[0][1])){scanf("%lf%lf",&len[1][0],&len[1][1]);scanf("%lf%lf",&len[2][0],&len[2][1]);fr = len[0][0]+len[0][1];se = len[1][0]+len[1][1];th = len[2][0]+len[2][1];ans = 0;ans = Max( ans,area(fr,se,th) );memset(vi,0,sizeof(vi));work(0,0);printf("%0.10lf\n",ans);}return 0;}




2 0
原创粉丝点击