- 北京2008的挂钟
- 2017-10-01 21:02:26 @
#include<cstdio>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
bool f=0;char _ch=getchar();_a=0;
while(_ch<'0'||_ch>'9'){if(_ch=='-')f=1;_ch=getchar();}
while(_ch>='0'&&_ch<='9'){_a=(_a<<1)+(_a<<3)+_ch-'0';_ch=getchar();}
if(f)_a=-_a;
}
struct node{ int clock[10],ser[10],caoz[1001],cnt; }team[50001];
inline void rush(int *clock,int *pre_clock,int type)
{
for (register int i=1;i<=9;++i) clock[i]=pre_clock[i];
switch(type)
{
case 1:
{
clock[1]=(pre_clock[1]+1)%4; //A
clock[2]=(pre_clock[2]+1)%4; //B
clock[4]=(pre_clock[4]+1)%4; //D
clock[5]=(pre_clock[5]+1)%4; //E
break;
}
case 2:
{
clock[1]=(pre_clock[1]+1)%4; //A
clock[2]=(pre_clock[2]+1)%4; //B
clock[3]=(pre_clock[3]+1)%4; //C
break;
}
case 3:
{
clock[2]=(pre_clock[2]+1)%4; //B
clock[3]=(pre_clock[3]+1)%4; //C
clock[5]=(pre_clock[5]+1)%4; //E
clock[6]=(pre_clock[6]+1)%4; //F
break;
}
case 4:
{
clock[1]=(pre_clock[1]+1)%4; //A
clock[4]=(pre_clock[4]+1)%4; //D
clock[7]=(pre_clock[7]+1)%4; //G
break;
}
case 5:
{
clock[2]=(pre_clock[2]+1)%4; //B
clock[4]=(pre_clock[4]+1)%4; //D
clock[5]=(pre_clock[5]+1)%4; //E
clock[6]=(pre_clock[6]+1)%4; //F
clock[8]=(pre_clock[8]+1)%4; //H
break;
}
case 6:
{
clock[3]=(pre_clock[3]+1)%4; //C
clock[6]=(pre_clock[6]+1)%4; //F
clock[9]=(pre_clock[9]+1)%4; //I
break;
}
case 7:
{
clock[4]=(pre_clock[4]+1)%4; //D
clock[5]=(pre_clock[5]+1)%4; //E
clock[7]=(pre_clock[7]+1)%4; //G
clock[8]=(pre_clock[8]+1)%4; //H
break;
}
case 8:
{
clock[7]=(pre_clock[7]+1)%4; //G
clock[8]=(pre_clock[8]+1)%4; //H
clock[9]=(pre_clock[9]+1)%4; //I
break;
}
case 9:
{
clock[5]=(pre_clock[5]+1)%4; //E
clock[6]=(pre_clock[6]+1)%4; //F
clock[8]=(pre_clock[8]+1)%4; //H
clock[9]=(pre_clock[9]+1)%4; //I
break;
}
}
}
inline bool check(int *clock)
{
for (register int i=1;i<=9;++i) if(clock[i]) return false;
return true;
}
int main()
{
int head=0,tail=1;
for (register int i=1;i<=9;++i) read(team[1].clock[i]);
while(head!=tail)
{
head=head%50000+1;
int now=head;
if(check(team[now].clock)){for (register int v=1;v<=team[now].cnt;++v)printf("%d ",team[now].caoz[v]);return 0;}
for (register int i=1;i<=9;++i)
{
if(team[now].ser[i]>=3) continue;
tail=tail%50000+1;
team[tail].cnt=team[now].cnt+1;
for (register int v=1;v<=9;++v) team[tail].ser[v]=team[now].ser[v];
++team[tail].ser[i];
for (register int v=1;v<team[tail].cnt;++v) team[tail].caoz[v]=team[now].caoz[v];
team[tail].caoz[team[tail].cnt]=i;
rush(team[tail].clock,team[now].clock,i);
}
}
}
0 条评论
目前还没有评论...