Codeforces round #265 (Div. 2) D. Restore cube

Source: Internet
Author: User

Peter had a cube with non-zero length of a side. he put the cube into three-dimen1_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 cocould swap some numbersinside a single line (Nick didn't swap numbers from distinct lines ). nick cocould have saved med 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 exceed106 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 inI-Th output line must be a permutation of the numbers inI-Th input line. The numbers shoshould 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. Give you eight points to rearrange the coordinates of any point and ask whether the cube can be formed. The idea is to arrange the coordinates of eight points and determine the Cube: look at the shortest edge and the oblique side of the surface and the relationship to the vertex.
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>typedef long long ll;using namespace std;ll a[10][10], b[10];ll dis(int i, int j) {ll x = a[i][0] - a[j][0];ll y = a[i][1] - a[j][1];ll z = a[i][2] - a[j][2];return x * x + y * y + z * z;}int check() {for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {if (i == j)continue;if (j < i)b[j] = dis(i, j);else b[j-1] = dis(i, j);}sort(b, b+7);ll t1 = b[0], t2 = 2 * b[0], t3 = 3 * b[0];if (t1 == 0 || t1 != b[1] || t1 != b[2] || t2 != b[3] || t2 != b[4] || t2 != b[5] || t3 != b[6])return 0;}return 1;}int isOk(int cur) {if (cur == 8) return check();sort(a[cur], a[cur]+3);do {if (isOk(cur+1))return 1;} while (next_permutation(a[cur], a[cur]+3));return 0;}int main() {for (int i = 0; i < 8; i++)cin >> a[i][0] >> a[i][1] >> a[i][2];if (!isOk(0))printf("NO\n");else {printf("YES\n");for (int i = 0; i < 8; i++){for (int j = 0; j < 3; j++)cout << a[i][j] << " ";printf("\n");}}return 0;}


Codeforces round #265 (Div. 2) D. Restore cube

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.