首页 > 代码库 > HDU 4801 Pocket Cube
HDU 4801 Pocket Cube
题目链接
去年现场,虎哥1Y的,现在刷刷题,找找状态...
一共6种转法,把3个面放到顶部,左旋和右旋,感觉写的还不错....都写成常数了。
#include <stdio.h>#include <math.h>#include <string.h>#include <queue>#include <algorithm>#define LL long longusing namespace std;struct node{ int num[24]; int st;};int dr[12] = {6,2,10,7,3,0,11,8,4,1,9,5};int dc[12] = {5,9,1,4,8,11,0,3,7,10,2,6};int a[12] = {2,3,5,6,7,8,11,12,13,14,16,17};int b[12] = {12,13,11,16,17,14,10,18,19,15,20,21};int c[12] = {0,2,22,4,5,6,20,10,11,12,18,16};int aim[6][4] = { {0,1,2,3}, {4,5,10,11}, {6,7,12,13}, {8,9,14,15}, {16,17,18,19}, {20,21,22,23} };int judge(int *p){ int ans = 0,i,j; for(i = 0;i < 6;i ++) { for(j = 1;j < 4;j ++) { if(p[aim[i][j]] != p[aim[i][0]]) break; } if(j == 4) ans ++; } return ans;}int main(){ node u,v; int n,i,ans; while(scanf("%d",&n)!=EOF) { for(i = 0;i < 24;i ++) { scanf("%d",&u.num[i]); } u.st = 0; queue<node>que; que.push(u); ans = 0; while(!que.empty()) { u = que.front(); que.pop(); if(ans == 6) break; ans = max(ans,judge(u.num)); if(u.st == n) continue; v.st = u.st + 1; //a for(i = 0;i < 24;i ++) { v.num[i] = u.num[i]; } for(i = 0;i < 12;i ++) { v.num[a[dr[i]]] = u.num[a[i]]; } que.push(v); for(i = 0;i < 12;i ++) { v.num[a[dc[i]]] = u.num[a[i]]; } que.push(v); //b for(i = 0;i < 24;i ++) { v.num[i] = u.num[i]; } for(i = 0;i < 12;i ++) { v.num[b[dr[i]]] = u.num[b[i]]; } que.push(v); for(i = 0;i < 12;i ++) { v.num[b[dc[i]]] = u.num[b[i]]; } que.push(v); //c for(i = 0;i < 24;i ++) { v.num[i] = u.num[i]; } for(i = 0;i < 12;i ++) { v.num[c[dr[i]]] = u.num[c[i]]; } que.push(v); for(i = 0;i < 12;i ++) { v.num[c[dc[i]]] = u.num[c[i]]; } que.push(v); } printf("%d\n",ans); } return 0;}
HDU 4801 Pocket Cube
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。