291 - The House Of Santa Claus

来源:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=4&problem=227&mosmsg=Submission+received+with+ID+14026069

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

题意:  一笔画问题。从1开始画,输出所有可能的情况
题解: DFS 只要用个数组 path保存下路径就可以了~~

AC代码:
#include<iostream>
using namespace std;
bool edge[6][6]={0},visit[6][6];
int path[10];
void dfs(int pos,int step){
	if(step==8){
		for(int i=0;i<9;i++)
		cout<<path[i];
		cout<<endl;
		return ;
	}
	for(int i=1;i<6;i++){
		if(edge[pos][i]&&visit[pos][i]){
			visit[pos][i]=false;
			visit[i][pos]=false;
			path[step+1]=i;
			dfs(i,step+1);
			visit[pos][i]=true;
			visit[i][pos]=true;
		}

	}
}
int main(){
	edge[1][2]=true;edge[1][5]=true;edge[1][3]=true;
	edge[2][1]=true;edge[2][5]=true;edge[2][3]=true;
	edge[3][2]=true;edge[3][5]=true;edge[3][4]=true;
	edge[3][1]=true;
	edge[4][3]=true;edge[4][5]=true;edge[5][3]=true;
	edge[5][4]=true;edge[5][1]=true;edge[5][2]=true;
	for(int i=0;i<6;i++)
		for(int j=0;j<6;j++)
			visit[i][j]=edge[i][j];
	path[0]=1;
	dfs(1,0);
	return 0;
}

291 - The House Of Santa Claus

时间: 2024-08-07 00:47:47

291 - The House Of Santa Claus的相关文章

UVA 291 The House Of Santa Claus DFS

题目: 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

UVa 291 The House Of Santa Claus 回溯dfs

题意:从左下方的1开始,一笔画出圣诞老人的房子. 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 int edge[6][6]; 5 6 //已画了k条边 准备将端点x加入进来 7 void dfs(int x,int k,string s){ 8 s+=char(x+'0'); 9 if(k==8){ 10 cout<<s<<endl; 11 return; 12 }

[2015-12-24]OMG美语每日笔记-Santa Claus

坚持学习英语,OMG口语非常长不错,坚持每天整理.学英语坚持最重要,学英语坚持最重要,学英语坚持最重要说三遍! Santa Claus is coming to town 圣诞老人进城来! There are so many Christmas songs about Santa .Santa Claus is coming to town.Is a classic example. 关于圣诞老人的歌很多,圣诞老人进城来,是一个比较经典的歌. Santa Baby 圣诞宝贝 I love lis

【Codeforces748D】Santa Claus and a Palindrome [STL]

Santa Claus and a Palindrome Time Limit: 20 Sec  Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个ai的贡献. 选出若干个串,若它们可以通过任意组合,形成一个回文串,则可以获得它们的贡献之和. 求最大贡献. Input 第一行两个整数k,n. 之后k行,每行分别是一个串si,与贡献ai. Output 一个整数表示答案. Sample Input 7 3 abb 2 aaa -3 bba -1 z

CodeForces - 748D Santa Claus and a Palindrome (贪心+构造)

题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的魅力值分别从大到小排序后,若两者之和大于0,则可以放在回文串的两边. 2.若某字符串是回文串,将其魅力值从大到小排序后,两两依次分析:(mid---可能放在回文串中间的串的最大魅力值) (1)若两个数都是正的,那么就将其放在两边,并将结果计入ans.(ans---回文串两边的串的魅力值之和) (2)

CodeForces - 748B Santa Claus and Keyboard Check

题意:给定两个字符串a和b,问有多少种不同的字母组合对,使得将这些字母对替换字符串b后,可以变成字符串a.注意字母对彼此各不相同. 分析:vis[u]记录与u可形成关系的字母,若u与v不同,则形成字母对.若之后该关系被打破,则输出-1. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib>

cf 478D.Santa Claus and a Palindrome

原来set,priority_queue也可以映射..涨姿势2333 比较麻烦的应该就是判断自身回文的串是选2个还是选一个吧. 1 #include<bits/stdc++.h> 2 #define INF 0x7fffffff 3 #define LL long long 4 #define N 100005 5 #define pill pair<int ,int > 6 using namespace std; 7 inline int ra() 8 { 9 int x=0,

UVA 291

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 In your childhood you most likely had to solve the riddle of the house of Santa Claus. Do

Educational Codeforces Round 79 (Rated for Div. 2) D. Santa&#39;s Bot

链接: https://codeforces.com/contest/1279/problem/D 题意: Santa Claus has received letters from n different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the i-th kid asked Santa to give them one of