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. get(0).tagName获得作用标签

    <script type="text/javascript" src="jquery1.4.js"></script><scrip ...

  2. 使用Visual VM 查看linux中tomcat运行时JVM内存

    前言:在生产环境中经常发生服务器内存溢出,假死或者线程死锁等异常,导致服务不可用.我们经常使用的解决方法是通过分析错误日记,然后去寻找代码到底哪里出现了问题,这样的方式也许会奏效,但是排查起来耗费时间 ...

  3. iOS.ChangeIniOS7

    1. Multitasking in iOS 7 http://www.objc.io/issue-5/multitasking.html http://www.slideshare.net/mrem ...

  4. Increase PHP script execution time with Nginx

    If you have a large WordPress setup or a server with limited resources, then you will often see the ...

  5. [JAVA]多线程下如何确定执行顺序性

    最近在讨论一个下载任务:要求文件下载后进行打包,再提供给用户下载: 如何确保打包的线程在所有下载文件的线程执行完成后进行呢? 看看下面三个兄弟的本事: CountDownLatch.CyclicBar ...

  6. linux fedora 的备份小技巧

    大家都知道,在fedora中,是没有默认安装带有GUI的备份软件的. 我们可以去软件中心搜索“备份”或者“dup”来安装deja-dup来进行备份,这个软件就是ubuntu中设置的“备份”,只不过ub ...

  7. 在Tomcat中部署Spring jpetstore

    第三篇:在Tomcat中部署Spring jpetstore 博客分类: Java之web SpringTomcatMySQLJDBCMVC  Spring samples中的jpetstore,基于 ...

  8. windows下tomcat+nginx+openssl配置双向认证

    1. 基础知识 CA证书:https://blog.csdn.net/yangyuge1987/article/details/79209473 SSL双向认证原理:https://blog.csdn ...

  9. 68.iOS设备尺寸及型号代码(iPhoneXR/XS)

    所有设备型号官网地址: https://www.theiphonewiki.com/wiki/Models iPhone: 机型 像素 比例 像素密度 屏幕尺寸 机型代码 发布日期 iPhone 2g ...

  10. 通俗理解 CPU && GPU

    CPU 力气大啥P事都能干,还要协调.GPU 上面那家伙的小弟,老大让他处理图形,这方面处理简单,但是量大,老大虽然能处理,可是老大只有那么几个兄弟,所以不如交给小弟处理了,小弟兄弟多,有数百至数千个 ...