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. 力特ZE398C驱动光盘-USB转RS232-支持Windows 10/Mac

    这个工具是USB1.1的,相对来说比较老,一开始做小白鼠不知道买了USB1.1的,所以我不建议买这个,还有其它的型号,支持USB2.0和USB3.0,不过价格也相对来说比较贵,这个才30块钱左右. 关 ...

  2. Windows Server 2016 Essentials试用

    下载地址: Windows Server 2016 Essentials (x64) SHA-1:        6E1D1880873157ADCEF3D74363308A95DC89103D ed ...

  3. The YubiKey -- HOW IT WORKS

    A single YubiKey has multiple functions for protecting access to your email, your apps and your phys ...

  4. Android 手电筒源代码

    近期因为公司须要,做了一个手电筒,事实上手电筒原理非常easy,就是调用照相机的闪光灯,控制闪光灯的开关,就能够实现手电筒的效果, 强调一下,代码中一定要注意在结束的时候对闪光灯进行释放,否则就会导致 ...

  5. 利用Spring MVC 上传图片文件

    本文转自:http://amcucn.iteye.com/blog/264457.感谢作者 近日在工作当中,需要用到上传图片的功能,然而自己平时学习的时候只会使用struts的上传功能,但因为项目并没 ...

  6. [翻译] FlatUIKit

    FlatUIKit FlatUIKit is a collection of iOS components styled with the "Flat UI" aesthetic ...

  7. apache基金会项目及甲骨文项目汇总

    Apache软件基金会 顶级项目 ▪ ActiveMQ ▪ Ant ▪ Apache HTTP Server ▪ APR ▪ Beehive ▪ Camel ▪ Cassandra ▪ Cayenne ...

  8. 《Java并发编程实战》第四章 对象的组合 读书笔记

    一.设计线程安全的类 在设计线程安全类的过程中,须要包括下面三个基本要素:  . 找出构成对象状态的全部变量.  . 找出约束状态变量的不变性条件.  . 建立对象状态的并发訪问管理策略. 分析对象的 ...

  9. Android4.2.2NDK和源代码开发jni的异同

    C/C++开发,在NDK和源代码中输出Log信息的方法! NDK: 1.包括头文件 #include <android/log.h> 2.Android.mk中包括库 LOCAL_LDLI ...

  10. elimination-game

    https://leetcode.com/problems/elimination-game/ // 一行代码就可以,不过原理有些复杂 // https://discuss.leetcode.com/ ...