棋盘覆盖问题
来源:互联网 发布:济南网络服务公司 编辑:程序博客网 时间:2024/06/16 07:00
#include <iostream>#include <algorithm>using namespace std;int num = 1;int chess[100][100];void FindChess(int tr, int tc, int dr, int dc, int size){ if (size == 1) return; int t=num++; int s = size / 2; if (dr < tr + s&&dc < tc + s)//左上角 { FindChess(tr, tc, dr, dc, s); } else { chess[tr + s - 1][tc + s - 1] = t; FindChess(tr, tc, tr + s - 1, tc + s - 1, s); } if (dr < tr + s&&dc >= tc + s)//右上角 { FindChess(tr, tc + s, dr, dc, s); } else { chess[tr + s - 1][tc + s] = t; FindChess(tr, tc+s, tr + s - 1, tc + s, s); } if (dr >= tr + s&&dc < tc + s)//左下角 { FindChess(tr + s, tc, dr, dc, s); } else { chess[tr + s][tc + s - 1] = t; FindChess(tr + s, tc, tr+s,tc + s - 1, s); } if (dr >= tr + s&&dc >= tc + s) { FindChess(tr + s, tc + s, dr, dc, s); } else { chess[tr + s][tc + s] = t; FindChess(tr + s, tc + s, tr + s, tc + s, s); }}int main(){ int k,posx,posy; cin >> k >> posx >> posy; FindChess(1, 1, posx, posy, k); for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) cout << chess[i][j] << " "; cout << endl; } system("pause");}
阅读全文
0 0
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- ChessBoard棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 《ChessboardCoverage_棋盘覆盖问题》
- 棋盘覆盖问题
- 棋盘覆盖问题
- 棋盘覆盖问题
- 在grub中添加win7(以及从win7来的win10)的启动项
- 富文本编辑器的使用
- Csharp中Thread的四种构造函数
- Python编程之文本编辑器
- SPSS MODELER支持的自动分类算法
- 棋盘覆盖问题
- ZOJ 2132 The Most Frequent Number 贪心
- 从对象深入分析 Java 中实例变量和类变量的区别
- 30天自制操作系统(第00天)
- 自学前端遇到瓶颈怎么办?
- matlab compiler & matlab coder
- 【POJ2718】Smallest Difference(枚举排列)
- handler内存泄露
- 从高考到程序员