8x8矩阵显示数字程序_在矩阵中填写8个数字

这是一个面试常考问题,目标是用1到8的数字填充8x8矩阵,确保相邻位置不出现连续数字。通过回溯算法解决,先选择空位,检查剩余数字,确保下一个数字不在相邻位置,放置正确数字并递归填充相邻空位。
摘要由CSDN通过智能技术生成

8x8矩阵显示数字程序

Description:

描述:

This is a standard interview problem to fill a matrix with 8 numbers using backtracking.

这是一个标准的面试问题,即使用回溯来用8个数字填充矩阵。

Problem statement:

问题陈述:

A matrix is given to you and eight vacant spaces are there. You have to fill the places with the digits 1 to 8 in a way that there are not any adjacent places filled with its next digits.

将为您提供一个矩阵,那里有八个空位。 您必须以1到8的数字来填充地点,以确保相邻的地方都不会填充其下一个数字。

Fill 8 numbers in a matrix (1)
    Input:
    An matrix given to you
    
    E.g.
    0 -1 -1 0
    -1 -1 -1 -1
    0 -1 -1 0
    
    Here -1 indicates the vacant places in the matrix.
    
    Output:
    Print the matrix with the numbers.

Example

    If the matrix is this:
    0 -1 -1 0
    -1 -1 -1 -1
    0 -1 -1 0

    Output:
    0 3 5 0
    7 1 8 2
    0 4 6 0

Fill 8 numbers in a matrix (2)

Explanation with example

举例说明

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值