hdu 5292 Pocket Cube

来源:互联网 发布:游戏产业 知乎 编辑:程序博客网 时间:2024/05/01 15:19

题目链接:hdu 5292 Pocket Cube


本来想用暴力,从还原的魔方出发,遍历出所有的可能。但是看了下官方题解,挺牛逼的。考虑每个颜色对(黄,白),对于顺时为+1,逆时位-1,原位置0。总和为3的倍数就是可以还原的,否则就是不能还原。连接


#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int bw[30] = {0, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, 0, 0, 0, 0, 1, -1, -1, 1};int main () {int cas;scanf("%d", &cas);for (int kcas = 1; kcas <= cas; kcas++) {int ret = 0;char s[2];for (int i = 1; i <= 24; i++) {scanf("%s", s);if (s[0] == 'w' || s[0] == 'y')ret += bw[i];}printf("Case #%d: %s\n", kcas, ret % 3 ? "NO" : "YES");}return 0;}


0 0
原创粉丝点击