暴力+枚举点用边长关系判断立方体
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long int LL;
LL a[8][3];
LL ta[8][3];
LL sig[8][3];
LL SQ(LL x)
{
return x*x;
}
LL Dist(int u,int v)
{
return SQ(ta[u][0]-ta[v][0])+SQ(ta[u][1]-ta[v][1])+SQ(ta[u][2]-ta[v][2]);
}
bool check()
{
for(int yuan=0;yuan<8;yuan++)
{
LL dist[8];
int nd=0;
for(int i=0;i<8;i++)
{
if(i==yuan) continue;
dist[nd++]=Dist(yuan,i);
}
sort(dist,dist+7);
if(dist[0]==0LL) return false;
if(dist[0]!=dist[1]||dist[0]!=dist[2]||dist[1]!=dist[2])
return false;
if(dist[3]!=dist[4]||dist[3]!=dist[5]||dist[4]!=dist[5])
return false;
if(dist[0]*2!=dist[3]) return false;
if(dist[0]*3!=dist[6]) return false;
}
return true;
}
int main()
{
for(int i=0;i<8;i++)
for(int j=0;j<3;j++)
{
cin>>a[i][j];
sig[i][j]=j;
}
do
{
do
{
do
{
do
{
do
{
do
{
do
{
do
{
for(int i=0;i<8;i++)
{
for(int j=0;j<3;j++)
{
ta[i][j]=a[i][sig[i][j]];
}
}
if(check())
{
puts("YES");
for(int i=0;i<8;i++)
{
for(int j=0;j<3;j++)
cout<<ta[i][j]<<" ";
cout<<endl;
}
return 0;
}
}while( next_permutation(sig[7],sig[7]+3) );
}while( next_permutation(sig[6],sig[6]+3) );
}while( next_permutation(sig[5],sig[5]+3) );
}while( next_permutation(sig[4],sig[4]+3) );
}while( next_permutation(sig[3],sig[3]+3) );
}while( next_permutation(sig[2],sig[2]+3) );
}while( next_permutation(sig[1],sig[1]+3) );
}while( next_permutation(sig[0],sig[0]+3) );
puts("NO");
return 0;
}