题目链接:Codeforces 464B Restore Cube
题目大意:给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值。问说8个点是否可以组成立方体。
解题思路:直接暴力枚举即可,保证一个点的坐标不变,枚举量为67,将上一层判断。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 8;
struct point {
ll x[3];
void input() {
for (int i = 0; i < 3; i++)
scanf("%lld", &x[i]);
}
void output() {
printf("%lld %lld %lld\n", x[0], x[1], x[2]);
}
point operator - (const point& u) {
point ret;
for (int i = 0; i < 3; i++)
ret.x[i] = x[i] - u.x[i];
return ret;
}
}p[maxn+5];
ll dis (point u) {
ll ret = 0;
for (int i = 0; i < 3; i++)
ret += u.x[i] * u.x[i];
return ret;
}
bool check (int k) {
int mv = 0;
ll d[maxn+5];
for (int i = 0; i < maxn; i++) {
if (i == k)
continue;
d[mv++] = dis(p[k] - p[i]);
}
sort(d, d + 7);
if (d[0] == 0)
return false;
if (d[0] != d[1] || d[0] != d[2])
return false;
if (d[3] != d[4] || d[3] != d[5])
return false;
if (d[0] * 2 != d[3] || d[0] * 3 != d[6])
return false;
return true;
}
bool judge () {
for (int i = 0; i < maxn; i++)
if (!check(i))
return false;
printf("YES\n");
for (int i = 0; i < maxn; i++)
p[i].output();
return true;
}
bool dfs (int d) {
if (d == maxn)
return judge();
sort(p[d].x, p[d].x + 3);
do {
if (dfs(d+1))
return true;
} while (next_permutation(p[d].x, p[d].x + 3));
return false;
}
int main () {
for (int i = 0; i < maxn; i++)
p[i].input();
if (!dfs(1))
printf("NO\n");
return 0;
}
分享到:
相关推荐
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
打codeforces的神器
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
Codeforces round 678 D2_Codeforces_源码
codeforces-js Codeforces JS
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
Codeforces Round #723 (Div. 2).md
接受串子-接受字符串相等-接受Codeforces回合#684(Div.2) 2/6 1440A-购买琴弦-接受1440B -中位数的总和-已接受1440C1-二进制表(简易版)-已接受1440C2-二进制表(硬版)-已接受 Codeforces回合#683(分区2) 1/...
Codeforces 题库 201-294 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。