UVa 10001 - Garden of Eden
来源:互联网 发布:python采集图片教程 编辑:程序博客网 时间:2024/06/10 00:34
这个题难点在理解题意,读了n遍都没有读懂,最后看的结题报告上的解释才明白它的意思。
题意:一共有256种自动机的编译形式,给你其中一种,你可以相应转换为对应的二进制数字串(即为表格中的一个New State),再根据这个标准编译串(New state)将给出的串逆转换,如果能逆转换成一个符合要求的新串则说明存在串可以转换为给出的串,则输出“REACHABLE”,否则不存在,输出“GARDEN OF EDEN”。
做法:dfs+判断,依次枚举给定的串中的数字对应的转换之前的连续邻接的三个数字,最后判断是否符合要求即可。
代码如下:
#include <iostream>#include <algorithm>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;char str[35];int a[35], code[10], c[35], n;int save[10][3] = { {0, 0, 0},{0, 0, 1},{0, 1, 0}, {0, 1, 1},{1, 0, 0},{1, 0, 1}, {1, 1, 0},{1, 1, 1} };int dfs(int cur){ if (cur == n - 1 || cur == n) { for (int i = 0; i < 8; i++) if (code[i] == a[cur] && save[i][0] == c[cur - 1] && save[i][1] == c[cur] && save[i][2] == c[cur + 1] ) { if (cur == n - 1 && !dfs(cur + 1)) return 0; else return 1; } return 0; } for (int i = 0; i < 8; i++) { if (a[cur] == code[i] && c[cur - 1] == save[i][0] && c[cur] == save[i][1] ) { c[cur + 1] = save[i][2]; if (dfs(cur + 1)) return 1; } } return 0;}int main(){#ifdef test freopen("sample.txt", "r", stdin);#endif int k ,num, flag; while (scanf("%d%d%s", &num, &n, str) == 3) { for (int i = 0; i < n; i++) a[i + 1] = str[i] - '0'; k = num; for (int i = 0; i < 8; i++) // 将对应数字转换为一种自动机(即一种New State) { code[i] = k % 2; k /= 2; } flag = 1; for (int i = 0; i < 8; i++) if (a[1] == code[i]) { c[0] = save[i][0]; c[1] = save[i][1]; c[2] = save[i][2]; c[n] = c[0]; c[n + 1] = c[1]; if (dfs(2)) { flag = 0; break; } } if(flag) printf("GARDEN OF EDEN\n"); else printf("REACHABLE\n"); } return 0;}
- UVa 10001 - Garden of Eden
- UVA 10001 Garden of Eden
- uva 10001 Garden of Eden
- UVA 10001 Garden of Eden
- UVa 10001 - Garden of Eden
- uva 10001 Garden of Eden (DFS)
- UVA - 10001 Garden of Eden (回溯)
- 10001 - Garden of Eden
- Garden of Eden uva +回溯
- UVa Problem 10001 Garden of Eden (伊甸园)
- 10001 - Garden of Eden(dfs)
- 10001 - Garden of Eden 题意解析
- Uva10001 Garden of Eden
- uva10001 - Garden of Eden
- uva10001 Garden of Eden
- hdu5977 Garden of Eden
- hdu5977 Garden of Eden
- HDU5977-Garden of Eden
- oracle基础之基本结构
- UVA 514 - Rails && POJ 1363 (堆栈模拟)
- 正则表达式30分钟入门教程
- EXcel 导入数据库和导出数据库的代码
- 何时调用C++复制构造函数和拷贝构造函数
- UVa 10001 - Garden of Eden
- SSH整合笔记
- 数据结构 -链表反转问题
- Win7 x64下配置apache和php
- 创新工场笔试
- Qt学习2——对话框改写
- CString.Format调用失败另一例(buffer too small vsprintf.c Line:244)
- [转载]Elsevier上发表论文的若干要求
- c primer plus chapter6