版权声明:是自己手打的没错 https://blog.csdn.net/Mr_Treeeee/article/details/82820416
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3752
题意:
给你3个人的上半身和下半身的长度。
问你组合后能形成的最大面积的三角形是多大。
一个人的上半身和下半身当然可以任意形成角度,但是不能分开。合理
point:
排列组合然后判断一个人有没有被分开。合理的话就可以算一次面积了。
注意排列组合如果要用next_permutation。不要按照长度来全排列。因为一个人的长度可能是相同的。但是不同的组合还是要考虑到。所以可以给这6个长度分别赋值123456,再开始全排列。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define LL long long
const int N = 1e5+33;
struct node
{
int len,k;
int c;
}a[10];
bool cmp(node a,node b)
{
return a.c<b.c;
}
bool f(int x)
{
for(int i=1;i<=6;i++){
if(a[i].k==x){
int to=i+1;
if(to==7) to=1;
int t=i-1;
if(t==0) t=6;
if(a[to].k!=x&&a[t].k!=x) return false;
return true;
}
}
return false;
}
bool check()
{
if(f(1)&&f(2)&&f(3)){
return true;
}
return false;
}
bool check(int a,int b,int c)
{
if(a+b<=c||b+c<=a||c+a<=b) return false;
return true;
}
int sum[7];
int main()
{
while(~scanf("%d",&a[1].len)){
double ans=0;
a[1].k=1;
a[1].c=1;
for(int i=2;i<=6;i++){
scanf("%d",&a[i].len);
a[i].k=(i+1)/2;
a[i].c=i;
}
do
{
if(check()){
for(int i=1;i<=6;i++){
sum[i]=sum[i-1]+a[i].len;
}
for(int i=1;i<=4;i++){
for(int j=i+1;j<=5;j++){
int a=sum[i],b=sum[j]-sum[i],c=sum[6]-sum[j];
if(check(a,b,c)){
double p=a+b+c;
p/=2;
ans=max(ans,sqrt(p*(p-a)*(p-b)*(p-c)));
}
}
}
}
}while(next_permutation(a+1,a+7,cmp));
printf("%.12lf\n",ans);
}
return 0;
}