码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 291

时间:2014-08-08 21:27:56      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   os   io   strong   for   

A - The House Of Santa Claus(11.2.1))
Crawling in process... Crawling failed
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

bubuko.com,布布扣

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.

  bubuko.com,布布扣
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.

  bubuko.com,布布扣
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






#include <iostream>
#include <cstring>
using namespace std;
int map[6][6];
void makemap()
{
    memset(map,0,sizeof(map));
    int i,j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
            if(i!=j)
                map[i][j]=1;

            map[1][4]=map[4][1]=0;
            map[2][4]=map[4][2]=0;
    }
}

void  dfs(int x,int k,string s)//DFS遍历,目前已生成长度为k-1的一笔画序列s,准备将x扩展为s的第k条边
{
    s=s+char(x+'0');//节点x进入访问序列
    if(k==8)//若完成了一笔画,则输出一笔画序列s
    {
        cout<<s<<endl;
        return;
    }
    int i;
    for(i=1;i<=5;i++)//按照节点序号递增的顺序访问邻接x未访问
    {
        if(map[x][i]!=0)
        {
            map[x][i]=map[i][x]=0;
            dfs(i,k+1,s);
            map[x][i]=map[i][x]=1;
        }
    }
}
int main()
{
    makemap();//生成无向图的相邻矩阵
    dfs(1,0,"");//从节点1出发计算所有可能的访问序列
}


UVA 291,布布扣,bubuko.com

UVA 291

标签:des   style   http   color   os   io   strong   for   

原文地址:http://blog.csdn.net/sunshumin/article/details/38443829

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!