皇后问题之C#版(非递归)
皇后问题之C#版(非递归)
作者:未知
日期:2005-08-30
人气: 3
投稿:(转贴)
来源:未知
字体:大 中 小
收藏:ASP.NET')">加入浏览器收藏
以下正文:
/*
*Author:Junyi Sun @CCNU
* E-mail:fxsjy@yahoo.com.cn
*/
using System;
namespace sunjoy
{
public class Queen
{
public static int Main()
{
int board_size = 0,x=0,y=0;//棋盘大小,当前行,当前列
uint solution_count = 0; //皇后摆放方案的个数
int[] rows, cols, slot1, slot2, x2y;//行占用情况,列占用情况,“/”状斜线占用情况,“\”状斜线占用情况,皇后坐标
DateTime t_start, t_end;
Console.WriteLine("请输入棋盘的大小");
try
{
board_size = Convert.ToInt32(Console.ReadLine());
if (board_size <= 0)
{
Console.WriteLine("非法数据");
return -1;
}
}
catch (Exception e) { Console.WriteLine("发生异常" e.Message); };
rows = new int[board_size];
cols = new int[board_size];
slot1 = new int[board_size * 2 - 1];
slot2 = new int[board_size * 2 - 1];
x2y = new int[board_size];
for (int i = 0; i < board_size; i )
x2y = -1; //坐标初始化都为-1
t_start = DateTime.Now;
while (true)
{
for (y = x2y[x] 1; y < board_size; y )
if (rows[x] == 0