codeforces 464B Restore Cube
给8个点, 判断这8个点能否组成一个正方体, 如果能, 输出这8个点。 同一个点的x, y, z可以交换。
每一个点有6种排列方式, 一个8个点, 暴力枚举出所有排列方式然后判断能否组成正方体。 判断的方法看代码。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int a[][];
ll dis[];
ll get_dis(int x, int y) {
ll ret = ;
for(int i = ; i<; i++) {
ret += 1LL*(a[x][i]-a[y][i])*(a[x][i]-a[y][i]);
}
return ret;
}
void output() {
puts("YES");
for(int i = ; i<; i++) {
for(int j = ; j<; j++) {
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int check() {
for(int center = ; center<; center++) {
int cnt = ;
for(int i = ; i<; i++) {
if(i == center)
continue;
dis[cnt++] = get_dis(i, center);
}
sort(dis, dis+);
if(dis[] == )
return ;
if(dis[]!=dis[]||dis[]!=dis[])
return ;
if(dis[]!=dis[]||dis[]!=dis[])
return ;
if(dis[]!= *dis[])
return ;
if(dis[] != *dis[])
return ;
}
return ;
}
int dfs(int d) {
if(d == ) {
if(check()) {
output();
return ;
}
return ;
}
sort(a[d], a[d]+);
do {
if(dfs(d+))
return ;
} while(next_permutation(a[d], a[d]+));
return ;
}
int main()
{
for(int i = ; i<; i++) {
for(int j = ; j<; j++) {
cin>>a[i][j];
}
}
if(!dfs()) {
puts("NO");
}
return ;
}
codeforces 464B Restore Cube的更多相关文章
- CodeForces 464 B Restore Cube
Restore Cube 题解: x->yyy 其实就是把x代替成yyy这个值. 如果不好理解的话, 可以试想一下, 刚开始的话 0->0, 1->1, 2->2,...,9- ...
- [Codeforces 1208D]Restore Permutation (树状数组)
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体判断
http://codeforces.com/contest/465/problem/D 给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值.问说8个点是否可以组成立方体. 暴力枚举即可, ...
- Codeforces Round #265 (Div. 2) D. Restore Cube 立方体推断
http://codeforces.com/contest/465/problem/D 给定8个点坐标.对于每一个点来说,能够任意交换x.y,z坐标的数值. 问说8个点能否够组成立方体. 暴力枚举就可 ...
- codeforces Restore Cube(暴力枚举)
/* 题意:给出立方体的每个顶点的坐标(是由源坐标三个数某几个数被交换之后得到的!), 问是否可以还原出一个立方体的坐标,注意这一句话: The numbers in the i-th output ...
- Codeforces 670F - Restore a Number - [字符串]
题目链接:https://codeforces.com/contest/670/problem/F 题意: 有一个非负整数 $n$,在它的右侧添上它的位数后,被发送出去:例如 $6510$,加上位数 ...
- Codeforces 1028E. Restore Array
题目直通车:http://codeforces.com/problemset/problem/1028/E 解法:设原数组为ar[],求ar中的最大值的下标ins,依次向前遍历一遍,每一个答案值都为前 ...
- codeforces A. Black-and-White Cube 解题报告
题目链接:http://codeforces.com/problemset/problem/323/A 题目意思:给定值 k ,需要输出 k 个 k 行 k 列的单位立方体各表示什么颜色(或者是黑色或 ...
- CodeForces–471D--MUH and Cube Walls(KMP)
Time limit 2000 ms Memory limit 262144 kB Polar bears Menshykov and Uslada from the zoo of ...
随机推荐
- Springmvc+Spring+Hibernate搭建方法及实例
Springmvc+Spring+Hibernate搭建方法及实例
- Openstack命令收集
查看rabbitmq 队列 rabbitmqctl list_queues 查看keystone的用户 keystone user-list 查看keystone endpoint keystone ...
- python邮件发送脚本
转自:http://phinecos.cnblogs.com/ #!/usr/bin/python #coding=utf-8 #@author:dengyike #@date:2010-09-28 ...
- ASP.NET之电子商务系统开发-4(二级分类)
一.前言 继上次的订单,这是第四篇.记录一下分类和筛选.这功能是最后做的,因为我完全不懂其原理.后来通过同学的指导(一位很有天赋的同学,比我牛逼一个层次,同样是高三.:D),终于也是完成了.在写这篇博 ...
- [转]Ubuntu 软件安装、查找、卸载--apt-get、apt-cache命令安全
# apt-get update——在修改/etc/apt/sources.list或者/etc/apt/preferences之後运行该命令.此外您需要定期运行这一命令以确保您的软件包列表是最新的. ...
- spark学习
大数据学习纲要,主要针对spark的相关知识的学习,后续会涉及其他大数据相关框架及语言. 1 spark入门: 2.spark 实战部分 3.spark源码解析
- easyui form提交文件(上传图片和文件)
<div id="dialogBtn"> <a class="easyui-linkbutton" href="#" on ...
- .net DataTable 取值辅助类
DataTableCommon类主要是帮助取值 方法列表: public static string GetCellString(DataTable dt,int row, int column) p ...
- [转]swift 学习资源 大集合
今天看到了一个swift的学习网站,里面收集了很多学习资源 [转自http://blog.csdn.net/sqc3375177/article/details/29206779] Swift 介绍 ...
- GDI+ 中发生一般性错误(在 OutputStream 中保存 PNG 格式图像时遇到的问题)
在将图片以 PNG 格式保存至 Response.OutputStream 时,会碰到如下错误: GDI+ 中发生一般性错误. 原因: 在写 PNG 格式的图像时,指针需要在存储的位置来回移动.而 R ...