HDU 2514 Another Eight Puzzle
来源:互联网 发布:类似网上邻居的软件 编辑:程序博客网 时间:2024/05/19 02:05
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2514
题意:每两个相连的点差要大于1。
代码:
#include <stdio.h>#include <string.h>#include <math.h>int Map[8][8] = {{ 0, 1, 1, 1, 0, 0, 0, 0 },{ 1, 0, 1, 0, 1, 1, 0, 0 },{ 1, 1, 0, 1, 1, 1, 1, 0 },{ 1, 0, 1, 0, 0, 1, 1, 0 },{ 0, 1, 1, 0, 0, 1, 0, 1 },{ 0, 1, 1, 1, 1, 0, 1, 1 },{ 0, 0, 1, 1, 0, 1, 0, 1 },{ 0, 0, 0, 0, 1, 1, 1, 0 } };int visit[10], in[10], ans[10]; // 搜索标记、输入、答案int sign; // sign==1时的输入数组直接用in[]int ABS(int x){if (x >= 0)return x;return -x;}int ok() // 判断当前搜索的一组是否符合{for (int i = 0; i < 8; i++)for (int j = 0; j < 8; j++)if (Map[i][j] && ABS(in[i] - in[j]) == 1)return 0;return 1;}void dfs(int a){if (a == 8 && ok()){sign++;for (int i = 0; i<8; i++){ans[i] = in[i];}}if (sign > 1)return;if (in[a] != 0)dfs(a + 1);for (int i = 1; i <= 8; i++){if (!visit[i]){visit[i] = 1;in[a] = i;dfs(a + 1);in[a] = 0;visit[i] = 0;}}}int main(){int t, Case = 0;scanf("%d", &t);while (t--){memset(visit, 0, sizeof(visit));for (int i = 0; i < 8; i++){scanf("%d", &in[i]);visit[in[i]] = 1;}sign = 0;dfs(0);printf("Case %d: ", ++Case);if (sign == 0)puts("No answer");else if (sign == 1){for (int i = 0; i < 7; i++)printf("%d ", ans[i]);printf("%d\n", ans[7]);}elseputs("Not unique");}return 0;}
0 0
- HDU 2514 Another Eight Puzzle
- hdu 2514 Another Eight Puzzle
- hdu 2514 Another Eight Puzzle
- hdu 2514 Another Eight Puzzle
- HDU 2514 Another Eight Puzzle
- hdu(2514) Another Eight Puzzle
- HDU 2514 Another Eight Puzzle
- hdu 2514 Another Eight Puzzle 枚举
- hdu 2514—— Another Eight Puzzle
- HDU 2514--Another Eight Puzzle【DFS】
- hdu 2514 Another Eight Puzzle(DFS+回溯)
- hdu 2514 Another Eight Puzzle 图填数字 next_permutation+暴力
- hdu 2514 Another Eight Puzzle(DFS暴搜)
- hdu 2541 Another Eight Puzzle(dfs)
- hdoj 2514 Another Eight Puzzle(DFS)
- hdu2514 Another Eight Puzzle
- Another Eight Puzzle
- Another Eight Puzzle
- linux的防火墙功能IP tables详解之二
- Extjs 4.2.0 MVC 架构
- 《高效学习OpenGL》之 视口变换 glViewport(), glDepthRange()
- AFX_EXT_CLASS
- 多层目录Makefile
- HDU 2514 Another Eight Puzzle
- 怎么用代码判断Android手机的Rom是MIUI及获取MIUI版本
- 多态和重载的区别
- cat > a.txt << EndOfFile
- 电视盒子的选购和使用技巧
- 应用反射技术改变ListView快速滑动条
- STL中list的排序算法
- Flex+Struts2结合实现文件下载
- linux拷贝文件夹