<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./No00.files/filelist.xml">
<title>八女王问题</title>
<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>a</o:Author>
<o:LastAuthor>a</o:LastAuthor>
<o:Revision>1</o:Revision>
<o:TotalTime>0</o:TotalTime>
<o:Created>1996-12-31T17:03:00Z</o:Created>
<o:LastSaved>1996-12-31T17:03:00Z</o:LastSaved>
<o:Pages>1</o:Pages>
<o:Company>aa</o:Company>
<o:Lines>1</o:Lines>
<o:Paragraphs>1</o:Paragraphs>
<o:Version>9.2812</o:Version>
</o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:UseFELayout/>
</w:Compatibility>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:1 135135232 16 0 262144 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:42.55pt;
mso-footer-margin:49.6pt;
mso-paper-source:0;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation' bgcolor="#e8ffe8">
<div class=Section1 style='layout-grid:15.6pt'>
<p class=MsoNormal align=center style='text-align:center'><span
style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>八女王问题</span></p>
<p class=MsoNormal><span lang=EN-US>/* "" </span><span
style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:
"Times New Roman"'>解法之二</span><span lang=EN-US>: </span><span style='font-family:
宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman"'>递归回溯算法</span><span
lang=EN-US> */<o:p><br>
<br>
</o:p></span></p>
<p class=MsoNormal><span
lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US>#include "stdio.h"<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>int count;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>int queen [10],
column[20],left[20],right[20];<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>void prt1()<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>{ int j;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>printf("No.%d<span style="mso-spacerun:
yes"> </span>",++count);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>for (j=1;j<=8;j++)
printf("%3d",queen[j]);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>printf("\n");<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>void try(int i)<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun: yes">
</span>{int j;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun: yes">
</span>for (j=1;j<=8;j++)<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>if (column[j] && left[i-j+8] &&
right[i+j])<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>{ queen[i]=j;<span style="mso-spacerun:
yes"> </span>column[j]=0;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>left[i-j+8]=0;<span
style="mso-spacerun: yes"> </span>right[i+j]=0;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>if (i<8)<span
style='mso-tab-count:1'> </span> try(i+1);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>else prt1();<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes">
</span>column[j]=left[i-j+8]=right[i+j]=1;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun: yes">
</span>}<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>main()<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>{int i;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun: yes">
</span>for (i=1;i<=16;i++)<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>column[i]=left[i]=right[i]=1;<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun: yes">
</span>count=0;<span style="mso-spacerun: yes"> </span>try(1);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><span style="mso-spacerun:
yes"> </span>}<o:p></o:p></span></p>
<p class=MsoNormal></p>
</div>
</body>
</html>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
No00.rar (1个子文件)
No00.htm 7KB
共 1 条
- 1
资源评论
zxsaw
- 粉丝: 3
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功