http://codeforces.com/contest/465/problem/D

给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值。问说8个点是否可以组成立方体。

暴力枚举即可,注意检查立方体姿势不对会T

如果8个点形成一个立方体是这样的:找到所有点对之间的最小距离,应等于边的长度L。每个顶点应该正好有三个点距离它为L,而且构成的三个边应两两垂直。如果这些条件都满足在每一点上,那么一定只能是立方体。检查复杂度约O(8^2)。

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
typedef pair<int, int> pii; const double eps = 1e-9;
const double pi = acos(-1.0); LL dianji(LL x1,LL y1,LL z1,LL x2,LL y2,LL z2)
{
return x1*x2+y1*y2+z1*z2;
}
LL dist2(LL x1,LL y1,LL z1,LL x2,LL y2,LL z2)
{
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);
}
LL v[8][3],minl[8],l;
int cntmin[8],to[8][8];
int index[8];
bool chuizhi(LL x1,LL y1,LL z1,LL x2,LL y2,LL z2)
{
return dianji(x1,y1,z1,x2,y2,z2) == 0;
}
bool chuizhi(int i,int a,int b)
{
return chuizhi(v[a][0] - v[i][0],v[a][1] - v[i][1],v[a][2] - v[i][2],v[b][0] - v[i][0],v[b][1] - v[i][1],v[b][2] - v[i][2]);
}
bool chuizhi(int i,int a,int b,int c)
{
return chuizhi(i,a,b)&&chuizhi(i,b,c)&&chuizhi(i,a,c);
}
bool check()
{
clr0(index),clr0(minl),clr0(cntmin);
for(int i = 0;i < 8;++i){
for(int j = i + 1;j < 8;++j){
l = dist2(v[i][0],v[i][1],v[i][2],v[j][0],v[j][1],v[j][2]);
if(!minl[i] || minl[i] > l)
minl[i] = l,to[i][cntmin[i] = 0] = j;
else if(minl[i] == l)
to[i][++cntmin[i]] = j;
if(!minl[j] || minl[j] > l)
minl[j] = l,to[j][cntmin[j] = 0] = j;
else if(minl[j] == l)
to[j][++cntmin[j]] = i;
}
if(cntmin[i]!=2 || !minl)
return false;
if(!chuizhi(i,to[i][0],to[i][1],to[i][2]))
return false;
}
return true;
}
bool find(int x)
{
if(x == 8){
return check();
}
do{
if(find(x+1))
return true;
}while(next_permutation(v[x],v[x]+3));
return false;
}
int main() {
for(int i = 0;i < 8;++i){
scanf("%I64d%I64d%I64d",&v[i][0],&v[i][1],&v[i][2]);
sort(v[i],v[i]+3);
}
if(!find(0))
puts("NO");
else{
puts("YES");
for(int i = 0;i < 8;++i){
printf("%I64d %I64d %I64d\n",v[i][0],v[i][1],v[i][2]);
}
}
return 0;
}

Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断的更多相关文章

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

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

  2. Codeforces Round #237 (Div. 2) C. Restore Graph(水构造)

    题目大意 一个含有 n 个顶点的无向图,顶点编号为 1~n.给出一个距离数组:d[i] 表示顶点 i 距离图中某个定点的最短距离.这个图有个限制:每个点的度不能超过 k 现在,请构造一个这样的无向图, ...

  3. Codeforces Round #350 (Div. 2) F. Restore a Number 模拟构造题

    F. Restore a Number   Vasya decided to pass a very large integer n to Kate. First, he wrote that num ...

  4. Codeforces Round #265 (Div. 1) C. Substitutes in Number dp

    题目链接: http://codeforces.com/contest/464/problem/C J. Substitutes in Number time limit per test 1 sec ...

  5. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...

  6. Codeforces Round #265 (Div. 2) E. Substitutes in Number

    http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...

  7. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...

  8. Codeforces Round #265 (Div. 2)

    http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...

  9. Codeforces Round #656 (Div. 3) B. Restore the Permutation by Merger

    题目链接:https://codeforces.com/contest/1385/problem/B 题意 有两个大小为 $n$ 的相同的排列,每次从二者或二者之一的首部取元素排入新的数组,给出这个大 ...

随机推荐

  1. XHR的对象及用法

    function  createXHR(){         //检测原生XHR对象是否存在,如果存在刚返回它的新实例:     //如果不存在,则检测ActiveX对象;     //如果两个都不存 ...

  2. 基于稀疏表(Sparse Table)的RMQ(区间最值问题)

    在RMQ的其他实现方法中,有一种叫做ST的算法比较常见. [构建] dp[i][j]表示的是从i起连续的2j个数xi,xi+1,xi+2,...xi+2j-1( 区间为[i,i+2j-1] )的最值. ...

  3. Maven 下载安装

    http://www.runoob.com/maven/maven-tutorial.html https://www.yiibai.com/maven/ Maven 提倡使用一个共同的标准目录结构, ...

  4. ES线程池

    每个Elasticsearch节点内部都维护着多个线程池,如index.search.get.bulk等,用户可以修改线程池的类型和大小,线程池默认大小跟CPU逻辑一致 一.查看当前线程组状态 cur ...

  5. zookeeper相关

    1.zookeeper应用:集群节点间的数据同步(资源管理),分布式锁(主要是利用客户端在一个会话中在zookeeper中创建一个znode节点,然后再去执行自己的业务代码,比如去更新数据库,其他客户 ...

  6. OCIlib的几个函数的执行效率(附上pro*c的性能对比)

    ocilib提供了以下几个执行sql语句的函数 OCI_ExecuteStmt/OCI_ExecuteStmtFmt 使用没有绑定变量的语句 OCI_Execute 使用有绑定变量的语句 OCI_Im ...

  7. PHP连接SQLServer2012两例

    首先放上 PHP连接SQLServer的驱动下载地址 http://php.net/manual/zh/ref.pdo-sqlsrv.php 另外PHP for IIS管理工具 大家可以自己搜索一下 ...

  8. SpringBoot的读取properties文件的方式

    转载:https://www.imooc.com/article/18252一.@ConfigurationProperties方式 自定义配置类:PropertiesConfig.java pack ...

  9. 技术课堂】如何管理MongoDB数据库?

  10. C++STL list

    list双向链表 高效进行插入删除数据 不可以随机存取元素,所以不支持at()和[]操作符.it可以++  --,不能it+5 节点序号从0开始 list<int> l; l.push_b ...