题意:给8个点三维坐标。你可以交换每个点的x,y,z,但只限于该点。问能否构成立方体。可以的话输出8个点。
思路:固定一个点的位置,枚举6^7种交换情况,判断是否可以构成立方体。详见代码:
// file name: codeforces464B.cpp //
// author: kereo //
// create time: 2014年09月08日 星期一 20时54分02秒 //
//***********************************//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=8;
const int inf=0x3fffffff;
const int mod=1000000000+7;
#define L(x) (x<<1)
#define R(x) (x<<1|1)
struct node
{
ll x[3];
}p[MAXN];
ll dis(ll x,ll y,ll z){
return x*x+y*y+z*z;
}
bool ok(int m){
int cnt=0;
ll a[MAXN];
for(int i=0;i<MAXN;i++){
if(i == m)
continue;
a[cnt++]=dis(p[m].x[0]-p[i].x[0],p[m].x[1]-p[i].x[1],p[m].x[2]-p[i].x[2]);
}
sort(a,a+8);
if(a[0] == 0)
return false;
if(a[0]!=a[1] || a[0]!=a[2])
return false;
if(a[3]!=a[4] || a[3]!=a[5])
return false;
if(a[0]*2!=a[3] || 3*a[0]!=a[6])
return false;
return true;
}
bool judge(){
for(int i=0;i<8;i++)
if(!ok(i))
return false;
printf("YES\n");
for(int i=0;i<8;i++)
printf("%lld %lld %lld\n",p[i].x[0],p[i].x[1],p[i].x[2]);
return true;
}
bool dfs(int d){
if(d == 8)
return judge();
sort(p[d].x,p[d].x+3);
do{
if(dfs(d+1))
return true;
}while(next_permutation(p[d].x,p[d].x+3));
return false;
}
int main()
{
for(int i=0;i<8;i++)
scanf("%lld%lld%lld",&p[i].x[0],&p[i].x[1],&p[i].x[2]);
if(!dfs(1))
printf("NO\n");
return 0;
}