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

13 篇文章 0 订阅
7 篇文章 0 订阅

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, while Guo 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 and Li (1 <= Ui, Li <= 150) indicates the height of two parts of the i-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 10
20 20
30 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;
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值