用唯一的行,列和3 * 3个小网格用数字1-9填充9 * 9网格 [英] filling 9*9 grid with numbers 1-9 with unique row, column and 3*3 small girds

查看:317
本文介绍了用唯一的行,列和3 * 3个小网格用数字1-9填充9 * 9网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须用9到9的数字填满9 * 9的网格.每行,每一列都应该是唯一的.
它与Sudoku拼图相同,但在Sudoku中我们已经填充了一些单元格.但是在这里,我只需要填充一个9 * 9的网格即可解决数独难题.

I have to fill 9*9 grid, with numbers from 1-9. Each row, column should be unique.
It is same as Sudoku puzzle but in Sudoku we have some cells already filled up. But here I''ve to just fill a 9*9 grid which will look solved Sudoku puzzle.

How can I implement the logic for this?

推荐答案

首先:由于结果应满足Sudoku规则,因此您未正确制定公式.请参阅: http://en.wikipedia.org/wiki/Sudoku [
First: as the result should satisfy Sudoku rules, you did not correctly formulate it. Please see: http://en.wikipedia.org/wiki/Sudoku[^].

Now, in you comment about available solution of Sudoku puzzle you failed to use very simple logic. Think about it: if you have an algorithm solving Sudoku puzzle, it also solves your problem. Isn''t this obvious? Or you need a proof? :-)

—SA


你好..
我试图了解您的问题,我认为这就是您想要的
hello..
i tried to understand your question and i think that''s what you want
namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args)
        {
            for (int i = 0; i <9; i++)
            {
                for (int x = 0; x < 9; x++)
                {
                    if ((x + 1 + i) > 9)
                    {
                        Console.Write("  {0}  ", (x + i + 1) % 9);
                    }
                    else
                    {
                        Console.Write("  {0}  ", (x + 1 + i));
                    }
                }
                Console.WriteLine("\n");
            }
            Console.Read();
        }
    }
}



输出将如下所示:
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8



and the output will be look like this:
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8


这篇关于用唯一的行,列和3 * 3个小网格用数字1-9填充9 * 9网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆