设为首页 加入收藏

TOP

Codeforces 464B Restore Cube(暴力)
2015-07-20 17:44:00 来源: 作者: 【 】 浏览:2
Tags:Codeforces 464B Restore Cube 暴力

题目链接:Codeforces 464B Restore Cube

题目大意:给定8个点坐标,对于每个点来说,可以随意交换x,y,z坐标的数值。问说8个点是否可以组成立方体。

解题思路:直接暴力枚举即可,保证一个点的坐标不变,枚举量为67,将上一层判断。

#include 
   
     #include 
    
      #include 
     
       #include 
      
        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; }
      
     
    
   
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ecshop 中分页的介绍 下一篇Codeforces 292D. Connected Comp..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)