第八届蓝桥杯第4题:方格分割
2018-03-26 19:38
295 查看
第八届蓝桥杯第4题:方格分割 6x6的方格,沿着格子的边线剪开成两部分。 要求这两部分的形状完全相同。 如图:p1.png, p2.png, p3.png 就是可行的分割法。 试计算: 包括这3种分法在内,一共有多少种不同的分割方法。 注意:旋转对称的属于同一种分割法。 请提交该整数,不要填写任何多余的内容或说明文字。
以位置3,3(格子)为起点相反方向的分割,遇到x == 0 或 6以及y == 0 或 6表示到达边界。 #include<iostream> #include<cstdio> #include<cstring> int mark[10][10]; int count_ = 0; int direction[4][2] = {1, 0, 0, 1, -1, 0, 0, -1}; using namespace std; void dfs(int x, int y); int main() { memset(mark, 0, sizeof(mark)); mark[3][3] = 1; dfs(3, 3); printf("%d\n", count_ / 4); return 0; } void dfs(int x, int y) { if (x == 0 || y == 0 || x == 6 || y == 6) { count_++; }else { for (int i = 0; i < 4; i++) { int temp_x = x + direction[i][0]; int temp_y = y + direction[i][1]; int temp_x2 = 6 - temp_x; int temp_y2 = 6 - temp_y; if (mark[temp_x][temp_y] == 0 && mark[temp_x2][temp_y2] == 0) { mark[temp_x][temp_y] = 1; mark[temp_x2][temp_y2] = 2; dfs(temp_x, temp_y); mark[temp_x][temp_y] = 0; mark[temp_x2][temp_y2] = 0; } } } }
相关文章推荐
- 第八届 蓝桥杯 c/c++ B组 省赛 (4)——方格分割
- 第八届蓝桥杯 方格分割
- 方格分割-第八届蓝桥杯c/c++组
- 蓝桥杯 方格分割 第八届
- 蓝桥杯第八届_方格分割
- 第八届蓝桥杯 dfs 方格分割
- 第八届蓝桥杯C++B组 方格分割
- 蓝桥杯第八届省赛JAVA真题----方格分割
- 第八届蓝桥杯【省赛试题4】方格分割
- 第八届蓝桥杯省赛真题 - 4.方格分割
- 2017第八届蓝桥杯省赛-大学A组 方格分割(深搜dfs)
- 第八届蓝桥杯省赛C/C++ A组第4题 方格分割
- 第八届蓝桥杯方格分割深搜
- 2017第八届蓝桥杯省赛Java A组--方格分割
- 第八届蓝桥杯C++B组第四题:方格分割
- 第八届蓝桥杯省赛B组c++_方格分割
- 第八届蓝桥杯第四题方格分割
- 第八届蓝桥杯第四题:方格分割
- 蓝桥杯第八届 方格分割(dfs)
- 蓝桥杯 方格分割(dfs)