(UVA 291)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. Well, a couple of years later, like now, you have to “draw” the house againbutonthecomputer. Asonepossibilityisnotenough, werequireall the possibilities when starting in the lower left corner. Follow the example in Figure 2 while defining your stretch. All the possibilities have to be listed in the outputfile by increasing order, meaning that 1234… is listed before 1235… .
在这里插入图片描述
在你的童年,你很可能要解开圣诞老人之家的谜语。你还记得重要的是在不提起铅笔,不画两次线的情况下把房子拉长吗?作为提醒,它必须看起来如图1所示。好吧,几年后,就像现在一样,你必须把房子“画”在电脑上。由于不可能,当从左下角开始时,我们就相当于有可能。在定义拉伸时,请遵循图2中的示例。所有的可能性都必须以递增的顺序列在输出文件中,这意味着1234…列在1235之前….

它的样例输出是乱写的emmm就只是告诉别人要递增,我还认真看了好久
无fa可说
用新get的string写哒
不能用printf输出string型

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

int line[6][6];

void Dfs(int x, int sum, string s) {
  s += char(x + '0');/*某人告诉我他新get的神奇写法*/
  if(sum == 8) {
    cout << s << endl;/*才知道不能用printf输出string型*/
    return;
  }
  for (int i = 1; i < 6; i++) {
    if (line[x][i]) {
      line[x][i] = line[i][x] = 0;
      Dfs(i,sum+1,s);
      line[x][i] = line[i][x] = 1;
    }
  }
}

int main(int argc, char const *argv[]) {
  memset(line,1,sizeof(line));
  line[1][4] = line[4][1] = line[2][4] = line[4][2] = 0;
  line[1][1] = line[2][2] = line[3][3] = line[4][4] = line[5][5] = 0;
  /*两点之间有连线的为1,其余为0*/
  Dfs(1, 0, "");
  return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44413445/article/details/89853623