HDU 4801搜索

13长沙水题 爆搜


#include "stdio.h"
#include "string.h"
#include "math.h"

struct comp
{
    int x[30];
} a;

int n,max;


void search(comp c)
{
    int ans;
    ans=0;
    if (c.x[0]==c.x[1] && c.x[0]==c.x[2] && c.x[0]==c.x[3]) ans++;
    if (c.x[6]==c.x[7] && c.x[6]==c.x[12] && c.x[6]==c.x[13]) ans++;
    if (c.x[8]==c.x[9] && c.x[8]==c.x[14] && c.x[8]==c.x[15]) ans++;
    if (c.x[4]==c.x[5] && c.x[4]==c.x[10] && c.x[4]==c.x[11]) ans++;
    if (c.x[16]==c.x[17] && c.x[16]==c.x[18] && c.x[16]==c.x[19]) ans++;
    if (c.x[20]==c.x[21] && c.x[20]==c.x[22] && c.x[20]==c.x[23]) ans++;

    if (ans>max) max=ans;

}

void dfs(int w,comp b)
{
    comp c;
    int t;
    if (w>n) return ;

    c=b;// 上顺
    t=c.x[2]; c.x[2]=c.x[3]; c.x[3]=c.x[1]; c.x[1]=c.x[0]; c.x[0]=t;
    t=c.x[6]; c.x[6]=c.x[8]; c.x[8]=c.x[23]; c.x[23]=c.x[4]; c.x[4]=t;
    t=c.x[7]; c.x[7]=c.x[9]; c.x[9]=c.x[22]; c.x[22]=c.x[5]; c.x[5]=t;
    search(c);
    dfs(w+1,c);

    c=b;// 上逆
    t=c.x[2]; c.x[2]=c.x[0]; c.x[0]=c.x[1]; c.x[1]=c.x[3]; c.x[3]=t;
    t=c.x[6]; c.x[6]=c.x[4]; c.x[4]=c.x[23]; c.x[23]=c.x[8]; c.x[8]=t;
    t=c.x[7]; c.x[7]=c.x[5]; c.x[5]=c.x[22]; c.x[22]=c.x[9]; c.x[9]=t;
    search(c);
    dfs(w+1,c);

    c=b;// 正顺
    t=c.x[6]; c.x[6]=c.x[12]; c.x[12]=c.x[13]; c.x[13]=c.x[7]; c.x[7]=t;
    t=c.x[2]; c.x[2]=c.x[11]; c.x[11]=c.x[17]; c.x[17]=c.x[8]; c.x[8]=t;
    t=c.x[3]; c.x[3]=c.x[5]; c.x[5]=c.x[16]; c.x[16]=c.x[14]; c.x[14]=t;
    search(c);
    dfs(w+1,c);

    c=b;// 正逆
    t=c.x[6]; c.x[6]=c.x[7]; c.x[7]=c.x[13]; c.x[13]=c.x[12]; c.x[12]=t;
    t=c.x[2]; c.x[2]=c.x[8]; c.x[8]=c.x[17]; c.x[17]=c.x[11]; c.x[11]=t;
    t=c.x[3]; c.x[3]=c.x[14]; c.x[14]=c.x[16]; c.x[16]=c.x[5]; c.x[5]=t;
    search(c);
    dfs(w+1,c);

    c=b; //侧顺
    t=c.x[8]; c.x[8]=c.x[14]; c.x[14]=c.x[15]; c.x[15]=c.x[9]; c.x[9]=t;
    t=c.x[3]; c.x[3]=c.x[13]; c.x[13]=c.x[19]; c.x[19]=c.x[23]; c.x[23]=t;
    t=c.x[1]; c.x[1]=c.x[7]; c.x[7]=c.x[17]; c.x[17]=c.x[21]; c.x[21]=t;
    search(c);
    dfs(w+1,c);

    c=b;//侧逆
    t=c.x[8]; c.x[8]=c.x[9]; c.x[9]=c.x[15]; c.x[15]=c.x[14]; c.x[14]=t;
    t=c.x[3]; c.x[3]=c.x[23]; c.x[23]=c.x[19]; c.x[19]=c.x[13]; c.x[13]=t;
    t=c.x[1]; c.x[1]=c.x[21]; c.x[21]=c.x[17]; c.x[17]=c.x[7]; c.x[7]=t;
    search(c);
    dfs(w+1,c);
}






int main()
{
    int i;
    while (scanf("%d",&n)!=EOF)
    {
        for (i=0;i<24;i++)
            scanf("%d",&a.x[i]);

        max=0;
        search(a);

        dfs(1,a);

        printf("%d\n",max);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值