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. slam14讲证明构成李代数

  2. POJ3417 Network

    一道LCA+树上差分 原题链接 显然每一条新增边都会导致环. 如果试着举些例子的话,很容易发现割掉非环上的边,则割掉其他任意一条新增边都可达成目标:若割掉的原有边是一个环上的边,那么只有割掉导致这个环 ...

  3. Lftp 简单使用步骤

    有一用户需要在Linux上面将数据备份至存储上面,但是不支持挂载. 只可以FTP. 找了下,Lftp 这款FTP Client 满足用户的需求. 相关资料参考:http://blog.chinauni ...

  4. Netty Reator(二)Scalable IO in Java

    Netty Reator(二)Scalable IO in Java Netty 系列目录 (https://www.cnblogs.com/binarylei/p/10117436.html) Do ...

  5. java 23种设计模式学习。

    一.3大类设计模式:创建型,结构型,行为型. a.5种创建型模式:工厂方法,抽象工厂,单例,建造者,原型. b.7种结构型模式:适配器,装饰器,代理,外观,桥接,组合,享元. c.11种行为型模式:策 ...

  6. RecyclerView错误

    1. java.lang.NoClassDefFoundError: android.support.v7.widget.RecyclerView 这个错误真TM见鬼,明明jar包里面就有这个类,工程 ...

  7. Java ClassLoad详解

    Java ClassLoad详解 类加载器是 Java 语言的一个创新,也是 Java 语言流行的重要原因之一.它使得 Java 类可以被动态加载到 Java 虚拟机中并执行.类加载器从 JDK 1. ...

  8. 51.从首页内容跳转到第二个Tabbar控制器(controller)

    TabBarController: 创建TabBar的控制器 注意:在点击的内容方法页面,添加头文件 #import "TabBarController.h" #import &q ...

  9. css初识和css选择器

    一.css是什么 css(cascading style sheet)定义如何显示HTML元素,给HTML设置样式,显得更为美观. 二.css的引入方式 1.行内引入 在标签中添加一个style是属性 ...

  10. 695. Max Area of Island

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...