(CF)B. Restore Cube (暴力枚举判断)

解决一道编程题,通过判断和排列八个顶点坐标来确定它们是否可以构成一个立方体。

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个点构成的三角形要么是直角三角形要么是等边三角形。如果条件都满足的话那么这八个顶点肯定能组成立方体了。 

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
#include <ctime>
#define LL __int64
#define EPS 1e-8
using namespace std;
LL a[10][4];
double dis(LL x[3],LL y[3])
{
	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]);
}
void DFS(int k)
{
	if (k!=8)
	{
		sort(a[k],a[k]+3);
		do
		{
			DFS(k+1);
		}while(next_permutation(a[k],a[k]+3));
	}
	else
	{
		double f[10];
		for (int i=1;i<8;i++)
			for (int j=i+1;j<=8;j++)
				if (dis(a[i],a[j])==0) return;
		for (int i=2;i<=8;i++)
			f[i-2]=dis(a[1],a[i]);
		sort(f,f+7);
		int flag=1;
		if (f[0]<=EPS) return; 
		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])
			flag=0;
		if (flag==1) return;
		double g[3];
		g[0]=dis(a[1],a[2]);
		flag=0;
		for (int i=3;i<=8;i++)
		{
			g[1]=dis(a[1],a[i]);
			g[2]=dis(a[2],a[i]);
			sort(g,g+3);
			if (g[0]+g[1]!=g[2]&& (g[0]!=g[1] && g[1]!=g[2])) 
			{
				flag=1;
				break;
			}
		}
		if (flag) return;
		puts("YES");
		for (int i=1;i<=8;i++)
			printf("%I64d %I64d %I64d\n",a[i][0],a[i][1],a[i][2]);
		exit(0);
	}
}
int main()
{
	for (int i=1;i<=8;i++)
		scanf("%I64d%I64d%I64d",&a[i][0],&a[i][1],&a[i][2]);
	DFS(1);
	puts("NO");
	return 0;
}



在 IT 领域,“RESTORE”、“RECOVER”和“REBUILD”有着不同的含义、区别和适用场景: ### RESTORERESTORE”主要指的是将数据从备份中恢复到原始或指定的位置。它是一个将备份数据复制回系统的过程,通常用于在数据丢失、损坏或系统故障后恢复数据到之前的某个状态。例如,在数据库系统中,使用“RESTORE”操作可以将数据库备份文件恢复到数据库服务器上。像在 RMAN(Recovery Manager)中,有类似 `sys.dbms_backup_restore.restoreControlfileTo(cfname=>'/support2/OFA_V804/u1/oradata/dbs/ctrl1V804.ctl');` 这样的语句用于恢复控制文件,这就是典型的“RESTORE”操作应用 [^2]。 ### RECOVER “RECOVER”侧重于在数据恢复后,使系统或数据达到一致和可用的状态。它通常涉及到应用归档日志、重做日志等,以更新恢复的数据到最新的事务状态。在数据库恢复过程中,“RESTORE”只是将备份数据复制回来,而“RECOVER”则是对这些数据进行进一步的处理,确保数据的完整性和一致性。例如,在恢复数据库时,可能会先执行“RESTORE”操作将数据库备份恢复,然后再执行“RECOVER”操作应用归档日志,使数据库恢复到最新的事务状态。当恢复过程中可能会报错,要确定归档是否存在,因为所需要的归档并未被备份,所以可以进行 `open resetlog` 操作,这与“RECOVER”过程中处理归档日志等情况相关 [^4]。 ### REBUILD “REBUILD”通常用于重建某些对象或结构,以提高性能、修复损坏或更新配置。它可能涉及到重建索引、表空间、分区等。例如,当数据库中的索引出现碎片化,影响查询性能时,可以使用“REBUILD”操作来重建索引,使其更加紧凑和高效。与“RESTORE”和“RECOVER”不同,“REBUILD”并不一定依赖于备份数据,而是对现有对象进行重新构建。 ### 适用场景总结 - **RESTORE**:适用于数据丢失、损坏或系统故障后,需要将数据恢复到之前某个时间点的情况。 - **RECOVER**:在“RESTORE”操作之后,用于使恢复的数据达到最新的事务状态,确保数据的一致性和可用性。 - **REBUILD**:用于优化或修复系统中的对象,提高性能或解决特定的问题,而不是用于数据的恢复。 ### 示例代码 以下是在 Oracle 数据库中使用 RMAN 进行“RESTORE”和“RECOVER”操作的示例代码: ```sql -- RESTORE 操作示例 RMAN> RESTORE DATABASE; -- RECOVER 操作示例 RMAN> RECOVER DATABASE; ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值