(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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值