魔方 有些心得呢 感觉经此一役自己成长了很多

来源:互联网 发布:淘宝鹏飞运动怎么样 编辑:程序博客网 时间:2024/04/24 19:36
#include<stdio.h>
#include<math.h>
#include<queue>
using namespace std;
char a1,a2,a3,a4,a5,a6;
char b1,b2,b3,b4,b5,b6;
char c1,c2,c3,c4,c5,c6;
char d1,d2,d3,d4,d5,d6;


char e1,e2,e3,e4,e5,e6;
char f1,f2,f3,f4,f5,f6;
char g1,g2,g3,g4,g5,g6;
char h1,h2,h3,h4,h5,h6;


void plan_DL();
void plan_DR();
void plan_RU();
void plan_RD();
void plan_C();
void plan_CC();
void input();
void search();
void deal();


int flag;
int comp();
int front();
int behind();
int left();
int right();
int up();
int below();
int exchange();
int adda(int x);
int num;
queue<char>col;
int main()
{
flag=0;
num=0;
input();
    while(flag==0)
{
search();
}
return 0;
}




void input()
{
scanf("%c%c\n",&a1,&b1);
scanf("%c%c\n",&c1,&d1);
scanf("%c%c\n",&a2,&b2);
scanf("%c%c\n",&c2,&d2);
scanf("%c%c\n",&a3,&b3);
scanf("%c%c\n",&c3,&d3);
scanf("%c%c\n",&a4,&b4);
scanf("%c%c\n",&c4,&d4);
scanf("%c%c\n",&a5,&b5);
scanf("%c%c\n",&c5,&d5);
scanf("%c%c\n",&a6,&b6);
scanf("%c%c",&c6,&d6);
col.push(a1);
col.push(b1);
col.push(c1);
col.push(d1);
col.push(a2);
col.push(b2);
col.push(c2);
col.push(d2);
col.push(a3);
col.push(b3);
col.push(c3);
col.push(d3);
col.push(a4);
col.push(b4);
col.push(c4);
col.push(d4);
col.push(a5);
col.push(b5);
col.push(c5);
col.push(d5);
col.push(a6);
col.push(b6);
col.push(c6);
col.push(d6);
return ;
}


int comp()
{
if(front()==1||behind()==1||left()==1||right()==1||up()==1||below()==1)
{
return 1;
}
else return 0;
}


int up()
{
if(e1=='0'&&f1=='0'&&g1=='0'&&h1=='0')
{
return 1;
}
else return 0;
}


int below()
{
if(e2=='0'&&f2=='0'&&g2=='0'&&h2=='0')
{
return 1;
}
else return 0;
}


int left()
{
if(e3=='0'&&f3=='0'&&g3=='0'&&h3=='0')
{
return 1;
}
else return 0;
}


int right()
{
if(e4=='0'&&f4=='0'&&g4=='0'&&h4=='0')
{
return 1;
}
else return 0;
}


int front()
{
if(e5=='0'&&f5=='0'&&g5=='0'&&h5=='0')
{
return 1;
}
else return 0;
}


int behind()
{
if(e6=='0'&&f6=='0'&&g6=='0'&&h6=='0')
{
return 1;
}
else return 0;
}


void search()
{
a1=col.front();
col.pop();
b1=col.front();
col.pop();
c1=col.front();
col.pop();
d1=col.front();
col.pop();

a2=col.front();
col.pop();
b2=col.front();
col.pop();
c2=col.front();
col.pop();
d2=col.front();
col.pop();

a3=col.front();
col.pop();
b3=col.front();
col.pop();
c3=col.front();
col.pop();
d3=col.front();
col.pop();

a4=col.front();
col.pop();
b4=col.front();
col.pop();
c4=col.front();
col.pop();
d4=col.front();
col.pop();

a5=col.front();
col.pop();
b5=col.front();
col.pop();
c5=col.front();
col.pop();
d5=col.front();
col.pop();

a6=col.front();
col.pop();
b6=col.front();
col.pop();
c6=col.front();
col.pop();
d6=col.front();
col.pop();

    plan_DL();    
    plan_DR();    
    plan_RU();   
    plan_RD();
    plan_C();
    plan_CC();
    return ;
}


void plan_DL()
{
if(flag==0)
{
e1=a1;
f1=b1;
g1=c1;
h1=d1;

e2=c2;
f2=a2;
g2=d2;
h2=b2;

e3=a3;
f3=b3;
g3=c5;
h3=d5;

e4=a4;
f4=b4;
g4=c6;
h4=d6;

e5=a5;
f5=b5;
g5=d4;
h5=c4;

e6=a6;
f6=b6;
g6=d3;
h6=c3;
       
if(comp()==1)
{
flag=1;
printf("%d\n",exchange());
}
else
{
deal();
}
return ;
}
}


void plan_DR()
{
if(flag==0)
{
e1=a1;
f1=b1;
g1=c1;
h1=d1;

e2=b2;
f2=d2;
g2=a2;
h2=c2;

e3=a3;
f3=b3;
g3=d6;
h3=c6;

e4=a4;
f4=b4;
g4=d5;
h4=c5;

e5=a5;
f5=b5;
g5=c3;
h5=d3;

e6=a6;
f6=b6;
g6=c4;
h6=d4;
if(comp()==1)
{
flag=1;
printf("%d\n",exchange());
}
else
{
deal();
}
return ;
}
}


void plan_RU()
{
if(flag==0)
{
e1=a1;
f1=b5;
g1=c1;
h1=d5;

e2=a2;
f2=b6;
g2=c2;
h2=d6;

e3=a3;
f3=b3;
g3=c3;
h3=d3;

e4=b4;
f4=d4;
g4=a4;
h4=c4;

e5=a5;
f5=d2;
g5=c5;
h5=b2;

e6=a6;
f6=d1;
g6=c6;
h6=b1;
if(comp()==1)
{
flag=1;
printf("%d\n",exchange());
}
else
{
deal();
}
return ;
}
}


void plan_RD()
{
if(flag==0)
{
e1=a1;
f1=d6;
g1=c1;
h1=b6;

e2=a2;
f2=d5;
g2=c2;
h2=b5;

e3=a3;
f3=b3;
g3=c3;
h3=d3;

e4=c4;
f4=a4;
g4=d4;
h4=b4;

e5=a5;
f5=b1;
g5=c5;
h5=d1;

e6=a6;
f6=b2;
g6=c6;
h6=d2;
if(comp()==1)
{
flag=1;
printf("%d\n",exchange());
}
else
{
deal();
}
return ;
}
}


void plan_C()
{
if(flag==0)
{
e1=a1;
f1=b1;
g1=d3;
h1=b3;
e2=a2;
f2=b2;
g2=d4;
h2=b4;
e3=a3;
f3=c2;
g3=c3;
h3=d2;
e4=a4;
f4=c1;
g4=c4;
h4=d1;
e5=c5;
f5=a5;
g5=d5;
h5=b5;
e6=a6;
f6=b6;
g6=c6;
h6=d6;
if(comp()==1)
{
flag=1;
printf("%d\n",exchange());
}
else
{
deal();
}
return ;
}
}


void plan_CC()
{
if(flag==0)
{
e1=a1;
f1=b1;
g1=b4;
h1=d4;
e2=a2;
f2=b2;
g2=b3;
h2=d3;
e3=a3;
f3=d1;
g3=c3;
h3=c1;
e4=a4;
f4=d2;
g4=c4;
h4=c2;
e5=b5;
f5=d5;
g5=a5;
h5=c5;
e6=a6;
f6=b6;
g6=c6;
h6=d6;
if(comp()==1)
{
flag=1;
printf("%d\n",exchange());
}
else
{
deal();
}
return ;
}
}


void deal()
{
col.push(e1);
col.push(f1);
col.push(g1);
col.push(h1);
col.push(e2);
col.push(f2);
col.push(g2);
col.push(h2);
col.push(e3);
col.push(f3);
col.push(g3);
col.push(h3);
col.push(e4);
col.push(f4);
col.push(g4);
col.push(h4);
col.push(e5);
col.push(f5);
col.push(g5);
col.push(h5);
col.push(e6);
col.push(f6);
col.push(g6);
col.push(h6);
num=num+1;
return ;
}
int exchange()
{
int i;

for(i=1;adda(i)<num;i++)
{
;
}

return i-1;
}
int adda(int x)
{
int j;

int sum;

sum=0;

for(j=0;j<x;j++)
{
sum=sum+pow(6,j);
}
return sum;
}
原创粉丝点击