ZOJ Monthly, January 2014 F The Three Guys (浙江大学月赛)
2014-01-27 10:02
429 查看
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:
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.
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.
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;
}
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:
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;
}
相关文章推荐
- ZOJ Monthly, January 2014 E Diagonal (浙江大学月赛)
- ZOJ Monthly, June 2014 月赛BCDEFGH题题解
- 浙大月赛 ZOJ Monthly, March 2014(简单题的题解)
- 记次浙大月赛 134 - ZOJ Monthly, June 2014
- ZOJ Monthly, January 2014(2014省赛练习)
- ZOJ Monthly, June 2014部分题解
- ZOJ Monthly, January 2018
- ZOJ 3764 - ZOJ Monthly, March 2014 最大流最小割
- 137 - ZOJ Monthly, November 2014 - J Poker Face
- ZOJ Monthly, January 2018 - F The Limit
- ZOJ Monthly, June 2014 解题报告
- ZOJ Monthly, August 2014
- zoj 3839(ZOJ Monthly, November 2014)
- January 24th 模拟赛A T3【NOI2014模拟】数列 Solution
- ZOJ Monthly, January 2018 - J Distance
- January 31st 模拟赛A T2 【SHTSC2014】信号增幅仪 Solution
- USACO January 2014 Bronze Level
- usaco 月赛 2005 january watchcow
- ZOJ Monthly, August 2014
- ZOJ Monthly, August 2014