zl程序教程

您现在的位置是:首页 >  其它

当前栏目

codeforces Restore Cube(暴力枚举)

Codeforces 枚举 暴力 cube Restore
2023-09-14 08:57:55 时间

/*

 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 

 问是否可以还原出一个立方体的坐标,注意这一句话:

 The numbers in the i-th output line must be a permutation of the numbers in i-th input line!

 我们只要对输入的每一行数据进行枚举每一个排列, 然后检查时候能构成立方体就好了! 

 检查立方体:找到最小的边长的长度 l, 统计边长为l, sqrt(2)*l, sqrt(3)*l的边长

 条数,如果恰好分别为12, 12, 4那么就是立方体了... 

#include iostream 

#include cstdio 

#include cstring 

#include algorithm 

using namespace std;

typedef long long LL;

LL num[8][3], d[70];

LL dis(int i, int j){

 return (num[i][0]-num[j][0])*(num[i][0]-num[j][0]) +

 (num[i][1]-num[j][1])*(num[i][1]-num[j][1]) + 

 (num[i][2]-num[j][2])*(num[i][2]-num[j][2]);


if(dfs(cur+1)) return true;//得到当前的全排列之后,继续向下寻找 }while(next_permutation(num[cur], num[cur]+3));//枚举这一个行的每一个全排列 return false; int main(){ for(int i=0; i ++i) for(int j=0; j ++j) scanf("%lld", num[i][j]); if(!dfs(0)) printf("NO\n"); return 0; }

The eight queens puzzle is the problem of placing eight chess queens on an 8 8 chessboard so that no two queens threaten each other.