ZOJ 3736 Pocket Cube(暴力,魔方)

魔方的题,暴力睡过。1930ms,差点久挂了。大笑

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <deque>

#define LL long long
#define DB double
#define SI(a) scanf("%d",&a)
#define SD(a) scanf("%lf",&a)
#define SS(a) scanf("%s",a)
#define PF printf
#define MM(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a;i<b;i++) 
#define REPD(i,a,b) for(int i=a;i>b;i--)
#define INF 0x3f3f3f3f
#define EPS 1e-8
#define bug puts("bug")
using namespace std;
#define N 25
int tun1[3][4] = {
    2,3,1,0,
    7,6,12,13,
    8,9,15,14
};
int tun2[3][8] = {
    4,5,6,7,8,9,23,22,
    3,2,5,11,16,17,14,8,
    23,21,19,17,13,7,3,1,
};

struct nod{
    int re[N];
    void in() {
        REP(i,0,24) SI(re[i]);
    }
    int cc(int a,int b,int c,int d) {
        if(re[a]==re[b]&&re[b]==re[c]&&re[c]==re[d]) return 1;
        return 0;
    }
    int get() {
        int ret =0;
        if(cc(0,1,2,3)) ret++;
        if(cc(4,5,11,10)) ret++;
        if(cc(6,7,12,13)) ret++;
        if(cc(8,9,14,15)) ret++;
        if(cc(16,17,18,19)) ret++;
        if(cc(20,21,22,23)) ret++;
        return ret;
    }
    void oor(int k) {
        int t;
        t = re[tun1[k][3]];
        REPD(i,3,0) re[tun1[k][i]] = re[tun1[k][i-1]];
        re[tun1[k][0]] = t;

        t = re[tun2[k][7]];
        REPD(i,7,0) re[tun2[k][i]] = re[tun2[k][i-1]];
        re[tun2[k][0]] = t;

        t = re[tun2[k][7]];
        REPD(i,7,0) re[tun2[k][i]] = re[tun2[k][i-1]];
        re[tun2[k][0]] = t;
    }

    void l1(int k) {
        oor(k);
    }
    void l2(int k) {
        oor(k);oor(k);
        oor(k);
    }
} ini,tmp;
int pow(int k) {
    int ret = 1;
    while(k--) {
        ret *= 6;
    }
    return ret;
}
int ans = 0;
void solve(int c,int k) {
    for(int i=0;i<c;i++) {
        int t = k%6;k/=6;
        if(t<3)
           tmp.l1(t);
        else
           tmp.l2(t-3); 
    }
    ans = max(ans,tmp.get());
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    int n;
    while(~SI(n)) {
        ini.in();
        ans =0;
        for(int i=0;i<=n;i++) {
            int k = pow(i);
            for(int j=0;j<k;j++){
                tmp = ini;
                solve(i,j);
            }
        }
        PF("%d\n",ans);
    }
    return 0;
}


阅读更多
文章标签: 魔方 暴力
个人分类: 模拟
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭