Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
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 立方体判断的更多相关文章
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- Codeforces Round #237 (Div. 2) C. Restore Graph(水构造)
题目大意 一个含有 n 个顶点的无向图,顶点编号为 1~n.给出一个距离数组:d[i] 表示顶点 i 距离图中某个定点的最短距离.这个图有个限制:每个点的度不能超过 k 现在,请构造一个这样的无向图, ...
- 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 ...
- 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 ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2) E. Substitutes in Number
http://codeforces.com/contest/465/problem/E 给定一个字符串,以及n个变换操作,将一个数字变成一个字符串,可能为空串,然后最后将字符串当成一个数,取模1e9+ ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,现在要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #265 (Div. 2)
http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...
- Codeforces Round #656 (Div. 3) B. Restore the Permutation by Merger
题目链接:https://codeforces.com/contest/1385/problem/B 题意 有两个大小为 $n$ 的相同的排列,每次从二者或二者之一的首部取元素排入新的数组,给出这个大 ...
随机推荐
- 5O - 产生冠军
有一群人,打乒乓球比赛,两两捉对撕杀,每两个人之间最多打一场比赛. 球赛的规则如下: 如果A打败了B,B又打败了C,而A与C之间没有进行过比赛,那么就认定,A一定能打败C. 如果A打败了B,B又打败了 ...
- iOS.AutoLayout.2.CustomView-with-AutoLayout
Custom View Which Support AutoLayout 创建支持AutoLayout的Custom View AutoLayout 通过使view更加的自组织来减轻controlle ...
- 通过 ulimit 改善系统性能
系统性能一直是一个受关注的话题,如何通过最简单的设置来实现最有效的性能调优,如何在有限资源的条件下保证程序的运作,ulimit 是我们在处理这些问题时,经常使用的一种简单手段.ulimit 是一种 l ...
- 让delphi像C语言一样灵活
lazarus是免费的delphi 拥有和c语言一样的灵活性,见代码: procedure TForm1.FormCreate(Sender: TObject);var p:PIntegerArray ...
- PHP数组对象互转
//数组转对象 function array2object($array) { if (is_array($array)) { $obj = new StdClass(); foreach ($arr ...
- 基于centos6.5 hbase 集群搭建
注意本章内容是在上一篇文章“基于centos6.5 hadoop 集群搭建”基础上创建的 1.上传hbase安装包 hbase-0.96.2-hadoop2 我的目录存放在/usr/hadoop/hb ...
- Chrome firefox ie等浏览器空格( )兼容问题
使用( :)空格浏览器之间,显示的不一样,对不起等现象. 解决方案: 用半角空格&ensp:或者全角空格&emsp:就可以了,&ensp:相当于半格中文字符的宽 ...
- syslog系统日志、事件日志分析、EventLog Analyzer
syslog系统日志.事件日志分析.EventLog Analyzer Eventlog Analyzer是用来分析和审计系统及事件日志的管理软件,能够对全网范围内的主机.服务器.网络设备.数据库以及 ...
- 一道另类的区间dp题 -- P3147 [USACO16OPEN]262144
https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状 ...
- fabric 安装
fabric 是一个python的库,fabric可以通过ssh批量管理服务器. 第一步安装依赖包 安装fabric依赖及pip yum install -y python-pip gcc pytho ...