从google doc转移-8皇后
来源:互联网 发布:淘宝的面料跟材质 编辑:程序博客网 时间:2024/05/24 23:12
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
namespace zboDo.ACM
{
class EightQueen
{
private List<GridCell> ArrangedList;
public void printAllGridCells()
{
string s = string.Empty;
foreach (GridCell c in ArrangedList)
{
s += "{" + c.xValue + "," + c.yValue +"}";
}
//MessageBox.Show(s);
FileInfo t = new FileInfo(@"c:/result.txt");
TextWriter Tex = t.AppendText();
Tex.WriteLine(s);
Tex.Close();
}
public void Run()
{
ClearBeforeResult();
ArrangedList=new List<GridCell>();
int row=0;
int col = 0;
putCell(row, col);
}
private void ClearBeforeResult()
{
FileInfo t = new FileInfo(@"c:/result.txt");
if(File.Exists(@"c:/result.txt"))
{
t.Delete();
}
}
private void putCell(int row, int col)
{
while (row < 8)
{
GridCell cell = makeGridCell(row, col);
if (ISLegal(cell))
{
ArrangedList.Add(cell);
if (col < 7)
{
putCell(0, col + 1);
}
else
{
printAllGridCells();
this.RemovelastNode();
}
}
row++;
}
this.RemovelastNode();
col--;
}
private void RemovelastNode()
{
if(ArrangedList.Count>0)
ArrangedList.RemoveAt(ArrangedList.Count - 1);
}
private bool ISLegal(GridCell cell)
{
bool result=true;
foreach (GridCell gridCell in ArrangedList)
{
if (gridCell.xValue == cell.xValue) result = false;
else if (gridCell.yValue == cell.yValue) result = false;
else if (gridCell.yValue+gridCell.xValue == cell.yValue+cell.xValue) result = false;
else if (gridCell.yValue-gridCell.xValue == cell.yValue-cell.xValue) result = false;
}
return result;
}
private GridCell makeGridCell(int row, int col)
{
GridCell cell=new GridCell();
cell.xValue = row;
cell.yValue = col;
return cell;
}
class GridCell
{
public int xValue;
public int yValue;
}
}
}
- 从google doc转移-8皇后
- 从google doc转移-直接交换排序
- 从google doc转移-直接插入排序
- 从google doc转移-排球运动员站位
- Google doc
- google doc的使用
- Google doc 不能访问
- 中小型企业如何从微软的办公系统全面转移到Google Apps
- 从myspace转移完毕
- I will try google doc
- 从汉诺塔到八皇后问题
- 从Blogger向CSDN转移
- google gmail google+ google doc 等不能访问的办法
- 测试google doc 发布csdn blog
- 【词汇】Google doc & Cache、prefetch and cpu
- 使用google doc制作在线问卷调查表
- 无法访问google doc等的解决方法
- Google doc 無法訪問的解決方法
- 从google doc转移-直接插入排序
- jsp页面多文件上传(转)
- arcgis9.3 desktop的安装
- CS模式短信监控系统的设计与实现
- 包含文件 '../md5.asp' 不能用 '..' 表示父目录,IIS如何启用父目录
- 从google doc转移-8皇后
- 算术编码
- Transport Table Entries
- JPA简介
- Ajax Loading进度条gif在线生成网站Preloaders.net
- android build system links
- 从google doc转移-排球运动员站位
- arcgis server9.3 for java 安装
- window.showModalDialog用法介绍