291 - The House Of Santa Claus
Time limit: 3.000 seconds
291 - The House Of Santa Claus
Time limit: 3.000 secondsIn 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
话说学OI的时候,老师讲图的遍历,说了一个五角星图的遍历。。。这里有一个提交地址。
#include <iostream>
using namespace std;
int map[6][6]={ {0,0,0,0,0,0},
{0,0,1,1,0,1},
{0,1,0,1,0,1},
{0,1,1,0,1,1},
{0,0,0,1,0,1},
{0,1,1,1,1,0}};
void dfs(int x,int k,string s){
s+=char('0'+x);
if (k==8){
cout<<s<<endl;
return;
}
for (int i=1;i<=5;++i)
if (map[x][i]){
map[x][i]=0;
map[i][x]=0;
dfs(i,k+1,s);
map[x][i]=1;
map[i][x]=1;
}
return;
}
int main()
{
dfs(1,0,"");
return 0;
}
kdwycz的网站: http://kdwycz.com/
kdwyz的刷题空间:http://blog.csdn.net/kdwycz
本文介绍了一种解决圣诞老人之家图遍历问题的方法,通过使用深度优先搜索算法(DFS),实现了从左下角开始不重复经过每个节点的路径绘制,并列举了所有可能的遍历顺序。

1454

被折叠的 条评论
为什么被折叠?



