Codeforces Round #265 (Div. 2)D(判断立方体)

来源:互联网 发布:淘宝卖家虚拟交易步 编辑:程序博客网 时间:2024/04/28 03:58
B. Restore Cube
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Peter had a cube with non-zero length of a side. He put the cube into three-dimensional space in such a way that its vertices lay at integer points (it is possible that the cube's sides are not parallel to the coordinate axes). Then he took a piece of paper and wrote down eight lines, each containing three integers — coordinates of cube's vertex (a single line contains coordinates of a single vertex, each vertex is written exactly once), put the paper on the table and left. While Peter was away, his little brother Nick decided to play with the numbers on the paper. In one operation Nick could swap some numbers inside a single line (Nick didn't swap numbers from distinct lines). Nick could have performed any number of such operations.

When Peter returned and found out about Nick's mischief, he started recollecting the original coordinates. Help Peter restore the original position of the points or else state that this is impossible and the numbers were initially recorded incorrectly.

Input

Each of the eight lines contains three space-separated integers — the numbers written on the piece of paper after Nick's mischief. All numbers do not exceed 106 in their absolute value.

Output

If there is a way to restore the cube, then print in the first line "YES". In each of the next eight lines print three integers — the restored coordinates of the points. The numbers in the i-th output line must be a permutation of the numbers in i-th input line. The numbers should represent the vertices of a cube with non-zero length of a side. If there are multiple possible ways, print any of them.

If there is no valid way, print "NO" (without the quotes) in the first line. Do not print anything else.

Sample test(s)
input
0 0 00 0 10 0 10 0 10 1 10 1 10 1 11 1 1
output
YES0 0 00 0 10 1 01 0 00 1 11 0 11 1 01 1 1
input
0 0 00 0 00 0 00 0 01 1 11 1 11 1 11 1 1
output
NO

题意:给出八个三维的点,然后可以将每个点的三维坐标任意交换位置(只能是点内,不能是点间),问你最后能不能构成一个正方体

思路:这题我也是看错了题目,把立方体理解为了长方体= =

            这题显然可以暴搜,然后判断是否有一种状态可以构成立方体

            这么这题就转化为了给出8个点,判断是否能构成立方体

            显然比较巧妙的方法是枚举每个点,然后算出这个点与其它7个点的距离

            然后找出3个最小的距离(可以理解为长宽高),因为是立方体,所以这3个距离一定要相等
 
            然后相等还不够,还要判断与这3个距离对应的边是否两两垂直

            而且对于每个点算出的与其它7个点的最短距离要相等,然后就没啥了

0 0