The House Of Santa Claus
The House Of Santa Claus |
In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do you remember that the importance was on drawing the house in a stretch without lifting the pencil and not drawing a line twice? As a reminder it has to look like shown in Figure 1.
Figure: The House of Santa Claus
Well, a couple of years later, like now, you have to ``draw'' the house again but on the computer. As one possibility is not enough, we require all the possibilities when starting in the lower left corner. Follow the example in Figure 2 while defining your stretch.
Figure: This Sequence would give the Outputline 153125432
All the possibilities have to be listed in the outputfile by increasing order, meaning that 1234... is listed before 1235... .
Output
So, an outputfile could look like this:
12435123 13245123 ... 15123421
ACcode
#include <map> #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define ll long long int #define maxn 100005 #define mod 1000000007 #define INF 0x3f3f3f3f //int×î´óÖµ #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define MT(x,i) memset(x,i,sizeof(x)) #define PI acos(-1.0) #define E exp(1) using namespace std; int m[6][6]; void makemap(){ memset(m,0,sizeof(m)); FOR(i,1,5) FOR(j,1,5) if(i!=j) m[i][j]=1; m[4][1]=m[1][4]=0; m[4][2]=m[2][4]=0; } void dfs(int x,int k,string s){ s+=char(x+'0'); if(k==8){ cout<<s<<'\12'; return ; } FOR(y,1,5) if(m[x][y]){ m[x][y]=m[y][x]=0; dfs(y,k+1,s); m[x][y]=m[y][x]=1; } } int main(){ makemap(); dfs(1,0,""); return 0; }