/*
题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!),
问是否可以还原出一个立方体的坐标,注意这一句话:
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[][], d[]; LL dis(int i, int j){
return (num[i][]-num[j][])*(num[i][]-num[j][]) +
(num[i][]-num[j][])*(num[i][]-num[j][]) +
(num[i][]-num[j][])*(num[i][]-num[j][]);
} void out(){
for(int i=; i<; ++i){
printf("%lld", num[i][]);
for(int j=; j<; ++j)
printf(" %lld", num[i][j]);
printf("\n");
}
} int vis[][]; bool check(){
int cnt=;
int cnt1=, cnt2=, cnt3=;
LL L=(1LL)<<;
memset(vis, , sizeof(vis));
for(int i=; i<; ++i)
for(int j=; j<; ++j)
if(i!=j && !vis[i][j] && !vis[j][i]){
d[cnt++]=dis(i, j);
vis[i][j]=vis[j][i]=;
if(L>d[cnt-])
L=d[cnt-];
}
if(L==) return false;
for(int i=; i<cnt; ++i)
if(d[i] == L) cnt1++;
else if(d[i] == *L) cnt2++;
else if(d[i] == *L) cnt3++;
if(cnt1== && cnt2== && cnt3==) return true;
return false;
} bool dfs(int cur){
if(cur>=) return false;
sort(num[cur], num[cur]+);//排序
do{
if(check()){
printf("YES\n");
out();
return true;
}
if(dfs(cur+)) return true;//得到当前的全排列之后,继续向下寻找
}while(next_permutation(num[cur], num[cur]+));//枚举这一个行的每一个全排列
return false;
} int main(){
for(int i=; i<; ++i)
for(int j=; j<; ++j)
scanf("%lld", &num[i][j]);
if(!dfs())
printf("NO\n");
return ;
}

codeforces Restore Cube(暴力枚举)的更多相关文章

  1. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

  2. codeforces 466c(暴力枚举)

    题目链接 思路如下 *题意: 给定一个序列,问有多少种方案可以将此序列分割成3个序列元素和完全相同的子序列.(子序列不能为空).即问有多少个点对(i,j)满足a[1]+-+a[i-1]=a[i]+a[ ...

  3. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  4. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...

  5. Codeforces Round #298 (Div. 2) B. Covered Path 物理题/暴力枚举

    B. Covered Path Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/probl ...

  6. Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断

    http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...

  7. Codeforces 425A Sereja and Swaps(暴力枚举)

    题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...

  8. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  9. codeforces 464B Restore Cube

    题目链接 给8个点, 判断这8个点能否组成一个正方体, 如果能, 输出这8个点. 同一个点的x, y, z可以交换. 每一个点有6种排列方式, 一个8个点, 暴力枚举出所有排列方式然后判断能否组成正方 ...

随机推荐

  1. 在主方法中定义一个大小为10*10的二维字符型数组,数组名为y,正反对角线上存的是‘*’,其余 位置存的是‘#’;输出这个数组中的所有元素。

    //在主方法中定义一个大小为10*10的二维字符型数组,数组名为y,正反对角线上存的是‘*’,其余 位置存的是‘#’:输出这个数组中的所有元素. char [][]y=new char [10][10 ...

  2. 在dos中运行java程序,若出现Exception in thread “main" java.lang.NoClassDefFoundError

    在dos中运行java程序,若出现Exception in thread “main" java.lang.NoClassDefFoundError,可以检查一下几项: 环境变量配置: 注意 ...

  3. windows xp/7命令提示符强制结束指定进程

    开始----“运行 ”输入cmd ,然后在命令提示符下输入tasklist,出现如下列表: Image Name                     PID Session Name        ...

  4. android: SQLite使用 SQL 操作数据库

    虽然 Android 已经给我们提供了很多非常方便的 API 用于操作数据库,不过总会有一些 人不习惯去使用这些辅助性的方法,而是更加青睐于直接使用 SQL 来操作数据库.这种人 一般都是属于 SQL ...

  5. ES5 数组方法reduce

    reduce() 方法接收一个函数作为累加器(accumulator),数组中的每个值(从左到右)开始合并,最终为一个值. 参数 callback 执行数组中每个值的函数,包含四个参数 previou ...

  6. Spring+hibernate+struts

    一.Spring 主要功能:解耦和(对象之间可配置,依赖注入的) 1.概念: 容器:容器可以装载对象,实例化对象,配置对象之间的依赖关系. IOC/DIIOC:Inversion of Control ...

  7. zz Windows 10安装教程:硬盘安装Win10 系统步骤(适合32位和64位)

    Windows 10安装教程:硬盘安装Win10 系统步骤(适合32位和64位) Posted on 2015年01月28日 by 虾虾 22 Comments   最新的Windows 10 MSD ...

  8. 翻译:使用tbb实现特征检测的例子

    A feature-detection example using the Intel® Threading Building Blocks flow graph By Michael V. (Int ...

  9. java 调用微信截图工具

  10. 解决Electron加载带jquery的项目报错问题

    <!-- Insert this line above script imports --> <script>if (typeof module === 'object') { ...