Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
By SiamakIn Reply To:Time Limit Exceeded!!! Posted by:Blackwizard at 2012-04-20 16:34:48 Time:32MS Mem: 164K Solution : BfS #include <iostream> using namespace std; enum tag{A,B,C,D,E,F,G,H,I,END}; long move[9][6]={ { A , B , D , E ,END }, { A , B , C ,END }, { B , C , E , F ,END }, { A , D , G ,END }, { B , D , E , F , H ,END }, { C , F , I ,END }, { D , E , G , H ,END }, { G , H , I ,END }, { E , F , H , I ,END }, }; long add[9]={1,8,64,512,4096,32768,262144,2097152,16777216} ; long mod=0x036DB6DB ; int result[10] ,start; long getmove(long n , int num ,int b) { while(b--) for(int i=0;move[num-1][i]!=END;++i) { n+=add[ move[num-1][i] ]; n &= mod ; } return n; } int search(long clock,int dep) { if(clock==0) return 1; if(dep==10) return 0; for(int i=0;i<4 ;++i) if( search( getmove(clock,dep,i) , dep+1)==1 ) { result[dep-1]=i; return 1; } return 0; } int main() { long clock=0 ; for(int i=0;i<9;++i) { scanf("%d",&start); for(int j=0;j<start;++j) clock+=add[i]; } search(clock,1); for(int i=1;i<10;++i) for(int j=0;j<result[i-1];++j) printf("%d ",i); printf("\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator