poj2023 DFS
来源:互联网 发布:北京赛车pk10微信源码 编辑:程序博客网 时间:2024/05/24 07:37
/** * poj2023 DFS * 就是以前小时候常玩的那种做选择题然后翻页的那货,把每一页的内容都记下来以后用DFS的方法往下走就行了. * 第一个稍微麻烦的地方是输入,想办法把引号过掉,我这就用了最最原始的办法 * 第二个是可能会有循环的,或者貌似有多个解的,因此有正确答案以后要把正确答案的exist也设成true,这样只打印一次就行了,因为这个WA了3次 */#include <cstdio>#include <cstring>using namespace std;struct page{ char type; char content[257]; int a;//当为C类时,a b分别为跳转的两个页面,当为E类时,a为1表示HAPPY 为0表示Gd int b;} p[101];int path[101];bool exist[101];void dfs(int x,int stepnum){ if(exist[x]){ return; //该路线已经走过 } if(p[x].type == 'E' && p[x].a == 1){ //找到Happy ending,打印输出 for(int i=0;i<stepnum;++i){ printf("%s\n",p[path[i]].content); } printf("%s\n",p[x].content); exist[x] = true;//就是这句话 return ; } else if(p[x].type == 'E' && p[x].a == 0){ //GRISLY return; } else if(p[x].type == 'C'){ //p[x].type == 'C' exist[x] = true; path[stepnum] = x; dfs(p[x].a,stepnum+1); dfs(p[x].b,stepnum+1); exist[x] = false; }}int main(){ int t,k; char ending[10]; char temp; int idx; scanf("%d",&t); for(int tt=1;tt<=t;++tt){ scanf("%d",&k); memset(p,0,sizeof(p)); memset(path,0,sizeof(path)); memset(exist,0,sizeof(exist)); for(int i=1;i<=k;++i){ idx = 0; temp = 0; getchar();//\n scanf("%c",&p[i].type); getchar();// getchar();//" while(temp!='"'){ scanf("%c",&temp); p[i].content[idx++] = (temp=='"')? 0 : temp; } switch(p[i].type){ case 'C': scanf("%d%d",&p[i].a,&p[i].b); break; case 'E': scanf("%s",ending); p[i].a = (ending[0] == 'H') ? 1 : 0; break; default: break; } } printf("STORY %d\n",tt); dfs(1,0); } return 0;}
0 0
- poj2023 DFS
- DFS
- DFS
- dfs
- dfs
- dfs
- dfs
- DFS
- DFS
- dfs
- DFS
- DFS
- DFS
- dfs
- DFS
- dfs
- dfs
- dfs
- poj2001 字典树
- 测试时钟显示程序通过, 点阵显示 碰到一些困难 发现调试比写代码更纠结。代码没错 烧到板子里就是打不到想要的现象
- 用PNG透明图片和GDI+做不规则透明窗体
- poj2002 排序+哈希
- poj 1742 多重背包算法优化问题
- poj2023 DFS
- UVa 10000 - Longest Paths
- poj2038 模拟+next_permutation
- java 软引用 弱引用 缓存
- poj2051 优先队列(自实现版本和STL版本)
- Label的创建方法
- HDU 1072 Nightmare
- poj2157 BFS
- poj2182 线段树/线段数组+二分搜索