1. 程式人生 > >ZOJ 3736 Pocket Cube

ZOJ 3736 Pocket Cube

clu return dfs n) scanf include ++ algo ace

唯一思考點:左側順時針轉等價於右側逆時針轉,12種轉法變6種

類型:水題

總結:我很蠢

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define INF 0x7f7f7f7f
using namespace std;
typedef long long LL;
int a[24]; 
int ans,n;
int c[6][12]=
{{1,7,17,21,3,13,19,23,8,14,15,9},
{
21,17,7,1,23,19,13,3,9,15,14,8}, {4,6,8,23,5,7,9,22,0,2,3,1}, {23,8,6,4,22,9,7,5,1,3,2,0}, {0,9,19,10,1,15,18,4,20,22,23,21}, {10,19,9,0,4,18,15,1,21,23,22,20}}; void change(int x){ int t=a[c[x][0]]; a[c[x][0]]=a[c[x][1]]; a[c[x][1]]=a[c[x][2]]; a[c[x][2]]=a[c[x][3]]; a[c[x][3]]=t; t
=a[c[x][4]]; a[c[x][4]]=a[c[x][5]]; a[c[x][5]]=a[c[x][6]]; a[c[x][6]]=a[c[x][7]]; a[c[x][7]]=t; t=a[c[x][8]]; a[c[x][8]]=a[c[x][9]]; a[c[x][9]]=a[c[x][10]]; a[c[x][10]]=a[c[x][11]]; a[c[x][11]]=t; } int check(){ int res=0; if(a[6]==a[7]&&a[7
]==a[12]&&a[12]==a[13])++res; if(a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3])++res; if(a[8]==a[9]&&a[9]==a[15]&&a[15]==a[14])++res; if(a[16]==a[17]&&a[17]==a[18]&&a[18]==a[19])++res; if(a[20]==a[21]&&a[21]==a[22]&&a[22]==a[23])++res; if(a[4]==a[5]&&a[5]==a[10]&&a[10]==a[11])++res; return res; } void dfs(int c){ ans=max(ans,check()); if(c==n)return; for(int i=0;i<6;++i){ change(i); dfs(c+1); change(i^1); } return; } int main(){ while(~scanf("%d",&n)){ for(int i=0;i<24;++i) scanf("%d",&a[i]); ans=0; dfs(0); cout<<ans<<endl; } return 0; }

ZOJ 3736 Pocket Cube