| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1103 人关注过本帖
标题:棋盘问题?
只看楼主 加入收藏
yuucyf
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-9-15
收藏
 问题点数:0 回复次数:0 
棋盘问题?

棋盘覆盖问题向大家求助,希望大家能够帮帮忙呀!谢谢大家!!! 棋盘覆盖问题大家应该知道是什么问题,这里就不再多余了! 以下是源代码!!! #include<iostream> #include<stdlib.h> using namespace std ; void chessboard(int a[][] , int tr , int tc , int dr , int dc , int size) ; //其中*a[] 表示是二维数组 ,tr表示棋盘坐上角方格的行号 ,tc表示棋盘坐上角方格的列号 //dr表示特殊方格所在的行号 , dc表示特殊方格所在的列号 , size表示棋盘规格(既有几个格) void chessboard(int a[][] , int tr , int tc , int dr , int dc , int size) { int tile = 1 ; if(size == 1) return ; int t = tile++ ; //L型骨牌号 int s = size/2 ; //分割棋盘 //覆盖左上角棋盘 if(dr < tr+s && dc < tc+s) //特殊方格在此棋盘中 chessboard( a , tr , tc , dr , dc , s) ; else { //此棋盘中无特殊方格 //用t好L型骨牌覆盖右下角 a[tr+s-1][tc+s-1] = t ; //覆盖其余方格 chessboard(a , tr , tc , tr+s-1 , tc+s-1 , s) ; } //覆盖右上角棋盘 if(dr < tr+s && dc >= tc+s) //特殊方格在此棋盘中 chessboard(a , tr , tr+s , dr , dc , s) ; else { //此棋盘中无特殊方格 //用t好L型骨牌覆盖左下角 a[tr+s-1][tc+s] = t ; //覆盖其余方格 chessboard( a , tr , tc+s , tr+s-1 , tc+s , s) ; } //覆盖左下角棋盘 if(dr >= tr+s && dc < tc+s) //特殊方格在此棋盘中 chessboard(a , tr+s , tc , dr , dc , s) ; else { //此棋盘中无特殊方格 //用t好L型骨牌覆盖右上角 a[tr+s][tc+s-1] = t ; //覆盖其余方格 chessboard(a , tr+s , tc , tr+s , tc+s-1 , s) ; } //覆盖左下角棋盘 if(dr >= tr+s && dc >= tc+s) //特殊方格在此棋盘中 chessboard(a , tr+s , tc+s , dr , dc , s) ; else { //此棋盘中无特殊方格 //用t好L型骨牌覆盖左上角 a[tr+s][tc+s] = t ; //覆盖其余方格 chessboard(a , tr+s , tc+s , tr+s , tc+s , s) ; } }

int main() { int b[4][4] ; for(int i=0 ; i<=3 ; i++) for(int j=0 ; j<=3 ; j++) b[i][j] = 0 ; chessboard(b,0,0,0,1,16); for(int i=0 ; i<=3 ; i++) { for(int j=0 ; j<=3 ; j++) cout << b[i][j] << " " ; cout << endl ; } system("pause") ; }

搜索更多相关主题的帖子: 棋盘 
2005-09-15 22:55
快速回复:棋盘问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016686 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved