当前位置:   article > 正文

(CF)B. Restore Cube (暴力枚举判断)_b. restore modulo time limit per test1 second memo

b. restore modulo time limit per test1 second memory limit per test256 megab

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 0
0 0 1
0 0 1
0 0 1
0 1 1
0 1 1
0 1 1
1 1 1
output
YES
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
input
0 0 0
0 0 0
0 0 0
0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
output
NO


题意:给出8个顶点的坐标,每个顶点的x,y,z值被打乱了。问是否这8个顶点构成一个立方体,能的话就输出YES,并按照顺序输出8个顶点坐标。否则输出NO.

题解思路:首先每个顶点有6种状态,共8个点,所以枚举6的8次方个状态。用next_permutation枚举。然后进行判断。有两点重合肯定不是立方体,然后以一点到另外7点的距离是有规律的。前三个相等,中间三个相等,最后一个。3 3 1 状态。(我这里是距离的平方)。然后以两点到另外6个点构成的三角形要么是直角三角形要么是等边三角形。如果条件都满足的话那么这八个顶点肯定能组成立方体了。 

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <cmath>
  7. #include <queue>
  8. #include <map>
  9. #include <stack>
  10. #include <list>
  11. #include <vector>
  12. #include <ctime>
  13. #define LL __int64
  14. #define EPS 1e-8
  15. using namespace std;
  16. LL a[10][4];
  17. double dis(LL x[3],LL y[3])
  18. {
  19. return (x[0]-y[0])*(x[0]-y[0])+(x[2]-y[2])*(x[2]-y[2])+(x[1]-y[1])*(x[1]-y[1]);
  20. }
  21. void DFS(int k)
  22. {
  23. if (k!=8)
  24. {
  25. sort(a[k],a[k]+3);
  26. do
  27. {
  28. DFS(k+1);
  29. }while(next_permutation(a[k],a[k]+3));
  30. }
  31. else
  32. {
  33. double f[10];
  34. for (int i=1;i<8;i++)
  35. for (int j=i+1;j<=8;j++)
  36. if (dis(a[i],a[j])==0) return;
  37. for (int i=2;i<=8;i++)
  38. f[i-2]=dis(a[1],a[i]);
  39. sort(f,f+7);
  40. int flag=1;
  41. if (f[0]<=EPS) return;
  42. if (f[0]==f[1] && f[1]==f[2] && f[3]==f[4] && f[4]==f[5] && 2*f[2]==f[3] && f[6]==f[5]+f[0])
  43. flag=0;
  44. if (flag==1) return;
  45. double g[3];
  46. g[0]=dis(a[1],a[2]);
  47. flag=0;
  48. for (int i=3;i<=8;i++)
  49. {
  50. g[1]=dis(a[1],a[i]);
  51. g[2]=dis(a[2],a[i]);
  52. sort(g,g+3);
  53. if (g[0]+g[1]!=g[2]&& (g[0]!=g[1] && g[1]!=g[2]))
  54. {
  55. flag=1;
  56. break;
  57. }
  58. }
  59. if (flag) return;
  60. puts("YES");
  61. for (int i=1;i<=8;i++)
  62. printf("%I64d %I64d %I64d\n",a[i][0],a[i][1],a[i][2]);
  63. exit(0);
  64. }
  65. }
  66. int main()
  67. {
  68. for (int i=1;i<=8;i++)
  69. scanf("%I64d%I64d%I64d",&a[i][0],&a[i][1],&a[i][2]);
  70. DFS(1);
  71. puts("NO");
  72. return 0;
  73. }



声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号