求解九位宫游戏的C语言核心代码
2009-09-08 07:54
176 查看
这是一个求解九位宫游戏的C语言核心代码: /*查找空格*/ int find(int tab[9][9],int i,int j){ int l,k,count=1; for(l=i;l<9;l++) for(k=j;k<9;k++) if(tab[l][k]==0){ backdata(tab,l,k,count); }/*end if1 */ return tab; } /*回溯*/ int backdata(int tab[9][9],int i,int j,int count){ int l,k,mark = 0; mark = solution(tab,i,j,count); if(mark == 0){ low[topl] = i; topl++; low[topr] = j; topr++; find(tab,i,j); } if(mark == 1){ l = low[topl]; topl--; k = row[topr]; topr--; count = tab[l][k]; backdata(tab,l,k,count); } } /*为空格寻找合适的数字*/ int solution(int tab[9][9],int low,int row,int count){ int m1,m2,i,mark; for(i=count;i<=9;i++){ m1 = decideRL(tab,i,low,row); m2 = decideCHECK(tab,i,low,row); if((m1 == 0)&&(m2 == 0)){ tab[low][row] = i; mark = 0; } else mark = 1; } return mark; } /*判断横和列*/ int decideRL(int tab[9][9],int value,int low,int row){ int j,mark=0; for(j=0;j<9;j++) if((tab[low][j]== value)||(tab[j][row])==value) mark = 1; return mark; } /* 判断小方正 */ int decideCHECK(int tab[9][9],int value,int low,int row){ int i,j,L,R,ls,ln,rs,rn,mark=0; L = low/3; R = row/3; if(L-1<=0) ls = 0; ls = L*3; ln = (L+1)*3-1; if(R-1<=0) rs = 0; rs = R*3; rn = (R+1)*3-1; for(i=ls;i<=ln;i++) for(j=rs;j<=rn;j++) if(tab[j] == value) mark = 1; return mark; } |
相关文章推荐
- C语言_基础代码_01
- C语言10个基础代码(if-else)
- C语言不考级无权在google提交代码c语言发明者亦不例外
- 生成静态文件的新闻系统核心代码
- C语言实现聊天工具钟的抖动窗口功能,代码很简单,思路也很简单
- java mapping生产静态页面核心代码
- 比特币系统采用的公钥密码学方案和ECDSA签名算法介绍——第二部分:代码实现(C语言)
- 400行代码编C语言控制台界版2048游戏,编写疯子一样的C语言代码
- 编程精粹--编写高质量C语言代码(1):假想编译程序
- Android版多线程下载器核心代码分享
- 如何快速查找C语言代码中的宏的值
- 【zz】C++开发者快速学习Objective-C语言核心语法
- C语言的反汇编代码
- VScode中自定义用户代码片段(C user snippet)自动生成C语言头文件排除重复包含
- 前端架构设计1:代码核心
- c语言里两个跳过错误输入代码的区别
- c语言细节中的文件归类代码
- 数值分析多种算法C语言代码-推荐
- discuz论坛apache日志hadoop大数据分析项目:清洗数据核心功能解说及代码实现
- C语言 文件操作解析详解及实例代码