Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

By Siamak

Posted by SiamakDeCode at 2012-04-20 22:42:57 on Problem 1166 and last updated at 2012-04-20 22:53:44
In 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator