/*
题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!),
问是否可以还原出一个立方体的坐标,注意这一句话:
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. Leetcode 38 Count and Say 传说中的递推

    class Solution { public: vector<string> vs_; Solution(){ "); vs_.push_back(t); ; i< ;+ ...

  2. 前端开发-Weex初试

    1 Weex介绍 weex是阿里2016年开源的一套跨移动端(Andriod/IOS/Wap)的前端框架,采用VUE,较React Native入门相对简单 官网地址 2 Weex安装与初始化 2.1 ...

  3. struts2 iterator排序

    因为存入数据库的数据可能不是按照我们想要的方式存进去的.这就导致取出来的时候,不是按照我们想要的方式排序.这时候就要利用struts2的iterator排序功能,按照我们想要的顺序排列. 首先.一个付 ...

  4. Android:改变Activity切换方式(转载)

    overridePendingTransition(enterAnim, exitAnim); Intent intent =new Intent(this,item2.class); startAc ...

  5. 扩展easyui 的表单验证

    easyui 的validatebox()提供了自定义验证的方法,为此我把一些常用的数据验证汇总了一下,代码如下: 代码 $.extend($.fn.validatebox.defaults.rule ...

  6. android 开发 简单的页面布局

    package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view ...

  7. 解决VS2010中在项目上右键鼠标,无“添加STS引用”菜单的问题

    解决方法:将Windows Identity Foundation SDK文件夹C:\Program Files (x86)\Windows Identity Foundation SDK\v3.5\ ...

  8. activemq安全设置 设置admin的用户名和密码

    ActiveMQ使用的是jetty服务器, 打开conf/jetty.xml文件,找到 <bean id="securityConstraint" class="o ...

  9. JavaScript-求时间差

    var date1=new Date(); //开始时间 alert("aa"); var date2=new Date(); //结束时间 var date3=date2.get ...

  10. 网页内容导出word/excel的js代码

    IE设置: 工具-> Internet选项-> 安全->自定义级别-> 对没有标记安全级别的ActiveX控件进行初始化  设为启用! 1.导出word //指定区域导出到Wo ...