您的位置:首页 > 其它

ZOJ 3752 The Three Guys(暴力)

2016-04-15 21:05 246 查看
暴力枚举所有的长度可能

#include <cstdio>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
const int maxn = 57;
#define MAXN 100005
#define ll long long

struct node
{
int pos;
int a,b;
friend bool operator<(const node &x,const node &y)
{
return x.pos<y.pos;
}
};

bool cheak(int a,int b,int c)
{
int d[3]={a,b,c};
sort(d,d+3);
if(d[0]+d[1]>d[2])return true;
return false;
}

double getS(int a,int b,int c)
{
double p=(a+b+c)/2.0;
return sqrt(p*(p-a)*(p-b)*(p-c));
}

int main()
{
node a[3];
while(cin>>a[0].a>>a[0].b)
{
int all=0;
for(int i=1;i<3;i++)
{scanf("%d%d",&a[i].a,&a[i].b),all+=a[i].a,all+=a[i].b;}
all+=a[0].a,all+=a[0].b;
a[0].pos=0;a[1].pos=1,a[2].pos=2;
double ans=0.0;
do
{
for(int i=0;i<2;i++)
{
swap(a[0].a,a[0].b);
for(int j=0;j<2;j++)
{
swap(a[1].a,a[1].b);
for(int k=0;k<2;k++)
{
swap(a[2].a,a[2].b);
vector<int >q;
for(int in=0;in<3;in++)q.push_back(a[in].a),q.push_back(a[in].b);
for(int hu=0;hu<6;hu++)
{
int duan1,duan2,duan3;
for(int p1=0;p1<6;p1++)
{
duan1=0;
for(int pp1=0;pp1<=p1;pp1++)
duan1+=q[pp1];
for(int p2=p1+1;p2<6;p2++)
{
duan2=0;
for(int pp2=p1+1;pp2<=p2;pp2++)duan2+=q[pp2];
duan3=all-duan1-duan2;
if(cheak(duan1,duan2,duan3))
{
ans=max(ans,getS(duan1,duan2,duan3));
}
}
}
int temp=q[0];
q.erase(q.begin());
q.push_back(temp);
}
}
}
}
}while(next_permutation(a,a+3));
printf("%.12f\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: