1/* 2 Question: Give the coordinates of each vertex of the cube (it is obtained after the three numbers of source coordinates are exchanged !), 3. Check whether the coordinates of a cube can be restored. Note this sentence: 4 the numbers in the I-th output line must be a permutation of the numbers in I-th input line! 5 6. Train of Thought: 7. We only need to enumerate each row of input data and arrange each row. Then, we just need to check whether it can constitute a cube! 8. Check the Cube: Find the minimum length of the side l, and calculate the number of side lengths of the side l, SQRT (2) * l, and SQRT (3) * L. If the length is exactly 12, 12, 4 is the cube... 10 */11 # include <iostream> 12 # include <cstdio> 13 # include <cstring> 14 # include <algorithm> 15 16 using namespace STD; 17 18 typedef long ll; 19 20 ll num [8] [3], d [70]; 21 22 ll DIS (int I, Int J) {23 return (Num [I] [0]-num [J] [0]) * (Num [I] [0]-num [J] [0]) + 24 (Num [I] [1]-num [J] [1]) * (Num [I] [1]-num [J] [1]) + 25 (Num [I] [2]-nu M [J] [2]) * (Num [I] [2]-num [J] [2]); 26} 27 28 29 void out () {30 for (INT I = 0; I <8; ++ I) {31 printf ("% LLD", num [I] [0]); 32 For (Int J = 1; j <3; ++ J) 33 printf ("% LLD", num [I] [J]); 34 printf ("\ n"); 35} 36} 37 38 int vis [8] [8]; 39 40 bool check () {41 int CNT = 0; 42 int cnt1 = 0, cnt2 = 0, cnt3 = 0; 43 ll l = (1ll) <60; 44 memset (VIS, 0, sizeof (VIS )); 45 for (INT I = 0; I <8; ++ I) 46 for (Int J = 0; j <8; ++ J) 47 if (I! = J &&! Vis [I] [J] &! Vis [J] [I]) {48 d [CNT ++] = DIS (I, j ); 49 vis [I] [J] = vis [J] [I] = 1; 50 if (L> d [cnt-1]) 51 L = d [cnt-1]; 52} 53 If (L = 0) return false; 54 for (INT I = 0; I <CNT; ++ I) 55 if (d [I] = L) cnt1 ++; 56 else if (d [I] = 2 * l) cnt2 ++; 57 else if (d [I] = 3 * l) cnt3 ++; 58 If (cnt1 = 12 & cnt2 = 12 & cnt3 = 4) return true; 59 return false; 60} 61 62 bool DFS (INT cur) {63 If (cur> = 8) return false; 64 sort (Num [cur], num [cur] + 3); // sort 65 do {66 If (Check () {67 printf ("Yes \ n"); 68 out (); 69 return true; 70} 71 If (DFS (cur + 1) return true; // after obtaining the current full arrangement, continue to search for 72} while (next_permutation (Num [cur], num [cur] + 3 )); // enumerate all rows of this row 73 return false; 74} 75 76 int main () {77 for (INT I = 0; I <8; ++ I) 78 for (Int J = 0; j <3; ++ J) 79 scanf ("% LLD", & num [I] [J]); 80 If (! DFS (0) 81 printf ("NO \ n"); 82 return 0; 83}
Codeforces restore cube (brute-force enumeration)