207 条题解
-
-1仲火夜的渔夫 LV 8 @ 2017-04-07 22:25:44
一来就写了个裸双宽然后就TLE80分了:P
标算我猜是应该是位运算记忆化双宽(因为我这么写的呗%%%%%%%
不过是新手第一次写双宽第一次写位运算所以代码还是很不洁简的
很诡异的是最后答案要排一下序。。。。。有大神告诉我为什么么位运算姑且用18位的01串表示每个钟的状态(00是12点01是3点···
啊说起来这个是位运算么,只是十进制与二进制的转化用来压缩状态便于记忆化。
嘛代码:type gdc=record num,bian,fang:longint; end; cry=record //致敬大成と瑞阳(^^ゞ loc:longint; fu:boolean; end; var m:array[1..9] of string; //9种处理 w1,w2:array[0..1000000] of gdc; //双宽的俩队列 zhi,t1,t2,ans1,ans2,x,i:longint; s:string; c:array[0..100000] of longint; v1,v2:array[0..1000000] of cry; //记忆化数组 function pow(x,y:longint):longint; var ans,i:longint; begin ans:=1; for i:= 1 to y do begin ans:=ans*x; end; exit(ans); end; function toten(s:string):longint; //转10进制 var i,num:longint; begin num:=0; for i:= length(s) downto 1 do begin num:=num+(ord(s[i])-48)*pow(2,length(s)-i); end; exit(num); end; function totwo(num:longint):string; //转二进制 var s:string;b:longint; begin b:=0; s:=''; while num<>0 do begin b:=num mod 2; s:=chr(b+48)+s; num:=num div 2; end; exit(s); end; function deal1(tar:longint;s:string):string; //顺时针处理 tar是指哪一个钟 var a,b:longint; begin a:=tar+tar-1;b:=tar+tar; if (s[a]='0') and (s[b]='0') then begin s[b]:='1' end else if (s[a]='0') and (s[b]='1') then begin s[a]:='1';s[b]:='0'; end else if (s[a]='1') and (s[b]='0') then begin s[b]:='1' end else if (s[a]='1') and (s[b]='1') then begin s[a]:='0';s[b]:='0'; end; exit(s); end; procedure work1(i,h:longint); var s:string; j:longint; begin s:=totwo(w1[h].num); if length(s)<18 then for j:= 1 to 18-length(s) do s:='0'+s; for j:= 1 to length(m[i]) do begin s:=deal1(ord(m[i][j])-64,s); end; w1[t1].num:=toten(s); end; function pan1_1(t1:longint):boolean; //队列1自我判重 begin if v1[w1[t1].num].fu then begin exit(false); end else begin v1[w1[t1].num].fu:=true; v1[w1[t1].num].loc:=t1; exit(true); end; end; function pan1_2(t1:longint):boolean; //队列1与2判断是否已连接 begin if (v2[w1[t1].num].fu) then begin ans1:=t1;ans2:=v2[w1[t1].num].loc; exit(true); end else exit(false); end; function deal2(tar:longint;s:string):string; var a,b:longint; begin a:=tar+tar-1;b:=tar+tar; if (s[a]='0') and (s[b]='0') then begin s[a]:='1';s[b]:='1' end else if (s[a]='0') and (s[b]='1') then begin s[a]:='0';s[b]:='0'; end else if (s[a]='1') and (s[b]='0') then begin s[a]:='0';s[b]:='1'; end else if (s[a]='1') and (s[b]='1') then begin s[b]:='0'; end; exit(s); end; procedure work2(i,h:longint); var j:longint;s:string; begin s:=totwo(w2[h].num); if length(s)<18 then for j:= 1 to 18-length(s) do s:='0'+s; for j:= 1 to length(m[i]) do begin s:=deal2(ord(m[i][j])-64,s); end; w2[t2].num:=toten(s); end; function pan2_2(t2:longint):boolean; begin if (v2[w2[t2].num].fu) then begin exit(false) end else begin v2[w2[t2].num].fu:=true; v2[w2[t2].num].loc:=t2;exit(true); end; end; function pan2_1(t2:longint):boolean; begin if (v1[w2[t2].num].fu) then begin ans1:=v1[w2[t2].num].loc; ans2:=t2; exit(true); end else begin exit(false); end; end; procedure bfs(h:longint); var i:longint; begin for i:= 1 to 9 do begin work1(i,h); w1[t1].bian:=h; w1[t1].fang:=i; if (pan1_2(t1)) then exit; // writeln(w1[t1].num,' ',t1); if (pan1_1(t1)) then inc(t1); end; for i:= 1 to 9 do begin work2(i,h); w2[t2].bian:=h; w2[t2].fang:=i; if (pan2_1(t2)) then exit; //writeln(w2[t2].num,' ',t2); if (pan2_2(t2)) then inc(t2); end; bfs(h+1); end; procedure predo; begin m[1]:='ABDE'; m[2]:='ABC'; m[3]:='BCEF'; m[4]:='ADG'; m[5]:='BDEFH'; m[6]:='CFI'; m[7]:='DEGH'; m[8]:='GHI'; m[9]:='EFHI'; end; procedure daoxu(zhi:longint); var tmp,i:longint; begin for i:= 1 to (zhi div 2) do begin tmp:=c[i]; c[i]:=c[zhi-i+1]; c[zhi-i+1]:=tmp; end; end; procedure qs(x,y:longint); var i,j,k,tmp:longint; begin i:=x;j:=y;k:=c[(x+y) div 2]; while i<=j do begin while (c[i]<k) do inc(i); while (c[j]>k) do dec(j); if (i<=j) then begin tmp:=c[i]; c[i]:=c[j]; c[j]:=tmp; inc(i); dec(j); end; end; if (x<j) then qs(x,j); if (i<y) then qs(i,y); end; procedure print; var x,i:longint; begin x:=ans1; zhi:=0; while x<>0 do begin inc(zhi); c[zhi]:=w1[x].fang; x:=w1[x].bian; end; daoxu(zhi); x:=ans2; while x<>0 do begin inc(zhi); c[zhi]:=w2[x].fang; x:=w2[x].bian; end; qs(1,zhi); for i:= 1 to zhi do begin write(c[i],' '); end; end; begin s:=''; for i:= 1 to 9 do begin read(x); if x=0 then s:=s+'00' else if x=1 then s:=s+'01' else if x=2 then s:=s+'10' else s:=s+'11'; end; w1[0].num:=toten(s); w1[0].bian:=-1; t1:=1; w2[0].num:=0; w2[0].bian:=-1; t2:=1; predo; bfs(0); // writeln(ans1,' ',ans2); print; end.
应该还是比较模块化的吧!
-
-12017-02-13 22:37:25@
哪位大牛帮忙看下错在哪了,谢谢蛤
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int dx[9][9]={
{1,1,0,1,1,0,0,0,0},
{1,1,1,0,0,0,0,0,0},
{0,1,1,0,1,1,0,0,0},
{1,0,0,1,0,0,1,0,0},
{0,1,0,1,1,1,0,1,0},
{0,0,1,0,0,1,0,0,1},
{0,0,0,1,1,0,1,1,0},
{0,0,0,0,0,0,1,1,1},
{0,0,0,0,1,1,0,1,1},
};
int start[3][3];
int goal[3][3];
int ans[20];
struct a{
int step;
int father;
int no;
int map[3][3];
}que[20000];
int temp[3][3];int judge(int taill)//判重 改SET
{
for(int i=1;i<taill;i++)
{
int k=0;
for(int s=0;s<3;s++)
for(int n=0;n<3;n++)
if(temp[s][n]==que[i].map[s][n])k++;
if(k==9)return 0;
}
return 1;
}
int jjudge()//判目标
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if(temp[i][j]!=goal[i][j])return 0;
return 1;
}
void bfs()
{
int u,v,head=0,tail=1;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
que[head].map[i][j]=start[i][j];
que[1].father=0;while(head<tail)
{
head++;
for(int i=0;i<9;i++){
memcpy(temp,que[head].map,sizeof(temp));
int k=0;
for(int t=0;t<3;t++)
for(int s=0;s<3;s++)
{
temp[t][s]+=dx[i][k];
temp[t][s]%=4;
k++;
}
if(judge(tail))
{
tail++;
memcpy(que[tail].map,temp,sizeof(que[tail].map));
que[tail].no=i;
que[tail].father=que[head].no;
if(jjudge())
{
u=tail,v=0;
while(u!=0){
ans[++v]=que[u].no;
u=que[u].father;
}
}
}
}
}
}
int main()
{
int i,j,n,s;
freopen("clock.in","r",stdin);
freopen("clock.out","w",stdout);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>start[i][j];
bfs();
for(i=1;i<=20;i++)cout<<ans[i]<<" ";
/*for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
cout<<dx[i][j];
cout<<endl;
}*/
return 0;
} -
-12016-09-19 00:28:44@
为什么全部都错
#include <iostream>
#include <vector>
#include <cstdlib>using namespace std;
int wat[9]; //0A 1B 2C 3D 4E 5F 6G 7H 8I//时钟
bool watp[9]; //false为这个表非12点,true为这个表是12点
int cmd[10]; //true为这个命令用过了,false为没用过vector <int> pan; //临时命令数组
vector <int> ans; //结果命令数组
int anslen; //结果数组长度,减少入栈,调用x.size()次数inline bool wpwat() //返回false九个钟不都是十二点,true为九个钟都是十二点
{
int i;
for(i=0;watp[i]&&i<9;++i);
if( i<9 )return false;
return true;
}inline void ptwat(int a,int k) //k==0:搜索调表, k!=0:回溯调表
{
if(k==0) //k==0:搜索调表
switch(a)
{
case 1:
wat[0]++; //调表
wat[0]%=4; //化为0 1 2 3
watp[0]= wat[0]==0? true:false; //判断是否为十二点
wat[1]++;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[3]++;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[4]++;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
break;
case 2:
wat[0]++;
wat[0]%=4;
watp[0]= wat[0]==0? true:false;
wat[1]++;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[2]++;
wat[2]%=4;
watp[2]= wat[2]==0? true:false;
break;
case 3:
wat[1]++;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[2]++;
wat[2]%=4;
watp[2]= wat[2]==0? true:false;
wat[4]++;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[5]++;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
break;
case 4:
wat[0]++;
wat[0]%=4;
watp[0]= wat[0]==0? true:false;
wat[3]++;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[6]++;
wat[6]%=4;
watp[6]= wat[6]==0? true:false;
break;
case 5:
wat[1]++;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[3]++;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[4]++;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[5]++;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
wat[7]++;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
break;
case 6:
wat[2]++;
wat[2]%=4;
watp[2]= wat[2]==0? true:false;
wat[5]++;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
wat[8]++;
wat[8]%=4;
watp[8]= wat[8]==0? true:false;
break;case 7:
wat[3]++;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[4]++;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[6]++;
wat[6]%=4;
watp[6]= wat[6]==0? true:false;
wat[7]++;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
break;
case 8:
wat[6]++;
wat[6]%=4;
watp[6]= wat[6]==0? true:false;
wat[7]++;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
wat[8]++;
wat[8]%=4;
watp[8]= wat[8]==0? true:false;
break;
case 9:
wat[4]++;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[5]++;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
wat[7]++;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
wat[8]++;
wat[8]%=4;
watp[8]= wat[8]==0? true:false;
break;
}
else //k!=0:回溯调表
switch(a)
{
case 1:
wat[0]+=3; //-1+4=+3 -1退表,+4便于下面取余
wat[0]%=4; //化为0 1 2 3
watp[0]= wat[0]==0? true:false; //判断是否为十二点
wat[1]+=3;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[3]+=3;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[4]+=3;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
break;
case 2:
wat[0]+=3;
wat[0]%=4;
watp[0]= wat[0]==0? true:false;
wat[1]+=3;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[2]+=3;
wat[2]%=4;
watp[2]= wat[2]==0? true:false;
break;
case 3:
wat[1]+=3;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[2]+=3;
wat[2]%=4;
watp[2]= wat[2]==0? true:false;
wat[4]+=3;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[5]+=3;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
break;
case 4:
wat[0]+=3;
wat[0]%=4;
watp[0]= wat[0]==0? true:false;
wat[3]+=3;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[6]+=3;
wat[6]%=4;
watp[6]= wat[6]==0? true:false;
break;
case 5:
wat[1]+=3;
wat[1]%=4;
watp[1]= wat[1]==0? true:false;
wat[3]+=3;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[4]+=3;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[5]+=3;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
wat[7]+=3;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
break;
case 6:
wat[2]+=3;
wat[2]%=4;
watp[2]= wat[2]==0? true:false;
wat[5]+=3;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
wat[8]+=3;
wat[8]%=4;
watp[8]= wat[8]==0? true:false;
break;case 7:
wat[3]+=3;
wat[3]%=4;
watp[3]= wat[3]==0? true:false;
wat[4]+=3;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[6]+=3;
wat[6]%=4;
watp[6]= wat[6]==0? true:false;
wat[7]+=3;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
break;
case 8:
wat[6]+=3;
wat[6]%=4;
watp[6]= wat[6]==0? true:false;
wat[7]+=3;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
wat[8]+=3;
wat[8]%=4;
watp[8]= wat[8]==0? true:false;
break;
case 9:
wat[4]+=3;
wat[4]%=4;
watp[4]= wat[4]==0? true:false;
wat[5]+=3;
wat[5]%=4;
watp[5]= wat[5]==0? true:false;
wat[7]+=3;
wat[7]%=4;
watp[7]= wat[7]==0? true:false;
wat[8]+=3;
wat[8]%=4;
watp[8]= wat[8]==0? true:false;
break;
}
return;
}inline void rdin() //输入命令表
{
int i;
int len1=pan.size();
/*
if( len1==ans.size() )
for(i=0;i<len1;++i)
if(pan[i]>ans[i])return;
*/
ans.resize(0);
for(i=0;i<len1;++i)
ans.push_back( pan[i] );
anslen=ans.size(); //记录ans结果长度
return;
}int dfs(int be) //搜索回溯
{
int len=pan.size();
if( len>=anslen )return 0; //剪枝,如果len>anslen,再搜只能更长;如果len==anslen,先搜到的结果最短
if( wpwat() ){/*if( pan.size()<=ans.size() )*/rdin();return 0;}
int i;
for(i=be;i<=9;++i)
{
if( cmd[i]>2 )continue;
cmd[i]++;
ptwat(i,0);
pan.push_back(i);
dfs(i);
ptwat(i,1);
pan.pop_back();
cmd[i]--;
}
return 0;
}int main()
{
int i,len;
for(i=0;i<9;++i)
{
cin>>wat[i];
watp[i]= wat[i]==0? true:false; //输入后初始化十二点判断表
}
ans.resize(40); //初始化结果数组很大
anslen=40; //初始化结果数组很大
dfs(1);
for(i=0;i<anslen;++i)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
} -
-12016-09-02 10:33:23@
#include <cstdio>
#include <cstring>int m[10][9] = {
{0,0,0,0,0,0,0,0,0},
{1,1,0,1,1,0,0,0,0},
{1,1,1,0,0,0,0,0,0},
{0,1,1,0,1,1,0,0,0},
{1,0,0,1,0,0,1,0,0},
{0,1,0,1,1,1,0,1,0},
{0,0,1,0,0,1,0,0,1},
{0,0,0,1,1,0,1,1,0},
{0,0,0,0,0,0,1,1,1},
{0,0,0,0,1,1,0,1,1},
};int reach(int p[9]){
int flag=1;
for(int i=0;i<9;i++)
flag*=p[i]==0;
return flag;
}void move(int p[9],int w){
for(int i=0;i<9;i++)
p[i]=(p[i]+m[w][i])%4;
}
int ans=1262144,path[10];
void dfs(int p[9],int c[10],int w,int dist){
if(reach(p)){
if(ans>dist){
ans=dist;
memcpy(path,c,sizeof(path));
}
return;
}
int t1[9],t2[10];
for(int i=w;i<=9;i++){
if(c[i]==3)
continue;
memcpy(t1,p,sizeof(t1));
memcpy(t2,c,sizeof(t2));
move(t1,i);
t2[i]++;
dfs(t1,t2,i,dist+1);
}
}int main(){
//freopen("in.txt","r",stdin);
int S[9],B[10]={0};
for(int i=0;i<9;i++)
scanf("%d",&S[i]);
dfs(S,B,1,0);
for(int i=1;i<=9;i++)
for(int j=1;j<=path[i];j++)
printf("%d ",i);
printf("\n");
return 0;
} -
-12016-08-18 21:05:34@
暴力
```
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
const int maxstate = 1000000 + 5;
const int INF = 1000000000;
int g[9];
int a[10], ans[10], msum = INF;
const int ord[10][10] = {{1,1,0,1,1,0,0,0,0},
{1,1,1,0,0,0,0,0,0},
{0,1,1,0,1,1,0,0,0},
{1,0,0,1,0,0,1,0,0},
{0,1,0,1,1,1,0,1,0},
{0,0,1,0,0,1,0,0,1},
{0,0,0,1,1,0,1,1,0},
{0,0,0,0,0,0,1,1,1},
{0,0,0,0,1,1,0,1,1},
};int main(){
freopen("in.txt", "r", stdin);
for (int i = 0; i < 9; i++) {
cin >> g[i];
if (g[i] == 1) g[i] = 3;
else if (g[i] == 3) g[i] = 1;
}for (a[0] = 0; a[0] < 4; a[0]++)
for (a[1] = 0; a[1] < 4; a[1]++)
for (a[2] = 0; a[2] < 4; a[2]++)
for (a[3] = 0; a[3] < 4; a[3]++)
for (a[4] = 0; a[4] < 4; a[4]++)
for (a[5] = 0; a[5] < 4; a[5]++)
for (a[6] = 0; a[6] < 4; a[6]++)
for (a[7] = 0; a[7] < 4; a[7]++)
for (a[8] = 0; a[8] < 4; a[8]++) {int time[9]={0}, sum=0, flag = 1;
for (int i = 0; i < 9; i++) {
sum += a[i];
for (int j = 0; j < 9; j++) {
time[i] += a[j] * ord[j][i];
}
if (time[i]%4 != g[i]) {
flag = 0;
break;
}
}
if (!flag) continue;
if (sum < msum) {
msum = sum;
memcpy(ans, a, sizeof(a));
}}
for (int i = 0; i < 9; i++) {
while (ans[i]--) cout << i+1 << " ";
}
cout << "\n";
return 0;
}
``` -
-12016-08-17 13:57:32@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 552 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
Accepted, time = 0 ms, mem = 556 KiB, score = 100啊~~万能的枚举就是比搜索强 我爱这枚举爱的深沉 只会做水题的Powder #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <iomanip> #include <cstdlib> using namespace std; int Clock[4][4], Map[4][4]; int Order(int k) { int c = k; while (c < 0) { c += 4; } while (c > 4) { c -= 4; } return c; } int main() { for (int i = 1; i <= 3; ++i) { for (int j = 1; j <= 3; ++j) { scanf("%d", &Clock[i][j]); Clock[i][j] = (4 - Clock[i][j]) % 4; } } for (Map[1][1] = 0; Map[1][1] <= 3; ++Map[1][1]) { for (Map[1][2] = 0; Map[1][2] <= 3; ++Map[1][2]) { for (Map[1][3] = 0; Map[1][3] <= 3; ++Map[1][3]) { Map[2][1] = Order(Clock[1][1] - Map[1][1] - Map[1][2]); Map[2][3] = Order(Clock[1][3] - Map[1][2] - Map[1][3]); Map[2][2] = Order(Clock[1][2] - Map[1][1] - Map[1][2] - Map[1][3]); Map[3][1] = Order(Clock[2][1] - Map[1][1] - Map[2][1] - Map[2][2]); Map[3][3] = Order(Clock[2][3] - Map[1][3] - Map[2][2] - Map[2][3]); Map[3][2] = Order(Clock[3][2] - Map[3][1] - Map[3][3] - Map[2][2]); if ((Map[2][1]+Map[3][1]+Map[3][2])%4==Clock[3][1] && (Map[2][3]+Map[3][2]+Map[3][3])%4==Clock[3][3] && (Map[2][2]+Map[1][1]+Map[1][3]+Map[3][1]+Map[3][3])%4==Clock[2][2]) { for (int i = 1; i <= 3; ++i) { for (int j = 1; j <= 3; ++j) { for (int k = 1; k <= Map[i][j]; ++k) { printf("%d ", (i - 1) * 3 + j); } } } printf("\n"); return 0; } } } } return 0; }
秒过无压力
-
-12016-02-26 12:40:31@
我使用BFS
293ms
c
#include<stdio.h>//This programme was found by Lee simpson.
#define temp 269999
#define num 0
#define none -1
struct node{
int map[10];
int father;
int depth;
int change;
}queue[270000];
int head,tail,hash[4][4][4][4][4][4][4][4][4]={0},opera[10][6]={0,0,0,0,0,0/*0*/,4,1,2,4,5,0/*1*/,3,1,2,3,0,0/*2*/,4,2,3,5,6,0,/*3*/3,1,4,7,0,0,/*4*/5,2,4,5,6,8/*5*/,3,3,6,9,0,0/*6*/,4,4,5,7,8,0/*7*/,3,7,8,9,0,0/*8*/,4,5,6,8,9,0/*9*/};
int judge(int n){
int i;
for(i=1;i<=9;i++){
if(queue[n].map[i]!=0)
return 0;
}
return 1;
}
int newnode(){
tail++;
return tail;
}
int judgeb(int n){
if(hash[queue[n].map[1]][queue[n].map[2]][queue[n].map[3]][queue[n].map[4]][queue[n].map[5]][queue[n].map[6]][queue[n].map[7]][queue[n].map[8]][queue[n].map[9]]==0){
return 1;
}
return 0;
}
int tip(int n){
hash[queue[n].map[1]][queue[n].map[2]][queue[n].map[3]][queue[n].map[4]][queue[n].map[5]][queue[n].map[6]][queue[n].map[7]][queue[n].map[8]][queue[n].map[9]]=1;
}
int cmp(const int *a,const int *b){return *(int *)a-*(int *)b;}
int main(){
int i,j,new,ans[1000],ansn,tmpb;
head=0,tail=0;
queue[head].father=none;
for(i=1;i<=9;i++)
scanf("%d",&queue[head].map[i]);
while(head<=tail){
for(i=1;i<=9;i++){
queue[temp]=queue[head];
for(j=1;j<=opera[i][num];j++){
queue[temp].map[opera[i][j]]++;
queue[temp].map[opera[i][j]]%=4;
}
if(judgeb(temp)==1){
tip(temp);
queue[temp].change=i;
queue[temp].father=head;
new=newnode();
queue[new]=queue[temp];
}
}
if(judge(head)==1){
ansn=0;
tmpb=head;
while(tmpb!=none){
ans[ansn]=queue[tmpb].change;
ansn++;
tmpb=queue[tmpb].father;
}
break;
}
head++;
}
qsort(ans,ansn,sizeof(ans[0]),cmp);
for(i=1;i<ansn;i++){
printf("%d ",ans[i]);
}
return 0;
}