题目连接:http://codeforces.com/contest/464/problem/B
题目描述:给你8组(x,y,z),问能不能通过 x, y, z 之间的交换使得这8个点组成一个立方体!!!!
解题思路:题解上写得是,先暴力所有排列 (3!)^8 ,然后check,check每个顶点到其余顶点的距离,如果是 l, sqrt(2)*l, sqrt(3)*l,且l 不为0
但是我比赛的时候居然害怕double 转 int 导致精度误差,然后再最后+eps!!!(这是个傻X的举动),这样正数没问题,但是对于-2 ,就顺利的变成-1.。。。。。
//#pragma comment(linker,"/STACK:102400000,102400000")
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define ll long long
#define db double
#define PB push_back
using namespace std;
const int N = 100005;
const db eps = 1e-7;
const db INF = 1e50;
int p[6][3] =
{
0, 1, 2,
0, 2, 1,
1, 0, 2,
1, 2, 0,
2, 0, 1,
2, 1, 0
};
struct Point
{
db x[3];
Point (db a=0,db b=0,db c=0){x[0]=a,x[1]=b,x[2]=c;}
void input()
{
int t;
for(int i = 0; i < 3; i++) scanf("%d", &t),x[i]=t;
}
Point operator - (const Point &t) const
{
return Point(x[0]-t.x[0],x[1]-t.x[1],x[2]-t.x[2]);
}
int operator * (const Point &t) const
{
int res=0;
for(int i=0;i<3;i++) res+=x[0]*t.x[0];
return res;
}
} a[8], b[8], c[8];
db dist(Point i,Point j)
{
return sqrt((i.x[0]-j.x[0])*(i.x[0]-j.x[0])+
(i.x[1]-j.x[1])*(i.x[1]-j.x[1])+
(i.x[2]-j.x[2])*(i.x[2]-j.x[2]));
}
int sgn(db t)
{
return t<-eps?-1:t>eps;
}
db dis[100];
bool check()
{
for(int i=0;i<8;i++)
{
int cnt=0;
for(int j=0;j<8;j++)
{
dis[cnt++]=dist(b[i],b[j]);
}
sort(dis,dis+cnt);
if(sgn(dis[0])!=0||sgn(dis[1])==0||sgn(dis[1]-dis[2])!=0
||sgn(dis[2]-dis[3])!=0||sgn(dis[4]-dis[3]*sqrt(2.0))!=0||
sgn(dis[4]-dis[5])!=0||sgn(dis[6]-dis[5])!=0||
sgn(dis[7]-dis[1]*sqrt(3.0))!=0) return false;
}
return true;
}
bool ok;
void dfs(int k)
{
if(k == 8)
{
if(check())
ok = true;
}
else
{
for(int i = 0; i < 6; i++)
{
for(int j = 0; j < 3; j++) b[k].x[j] = a[k].x[p[i][j]];
dfs(k + 1);
if(ok) return;
}
}
}
int main()
{
#ifdef PKWV
freopen("in.in", "r", stdin);
#endif // PKWV
for(int i = 0; i < 8; i++) a[i].input();
ok = false;
dfs(0);
if(ok)
{
printf("YES\n");
for(int i=0;i<8;i++)
for(int j=0;j<3;j++) printf("%d%c",(int)(b[i].x[j]),j==2?'\n':' ');
}else printf("NO\n");
return 0;
}