hdu 1181 (搜索BFS,深搜DFS,并查集)
2013-04-05 12:12
375 查看
点击打开链接
刚开始RE了好几次;
刚开始RE了好几次;
#include"stdio.h" #include"string.h" #include"queue" using namespace std; int f; int mark[26]; int map[26][26]; void bfs(int a) { queue<int>Q; int i,t; t=a; Q.push(t); mark[t]=1; while(!Q.empty()) { t=Q.front(); Q.pop(); for(i=0;i<26;i++) { if(map[t][i]==1&&mark[i]==0) { if(i==12) { f=1;break; } Q.push(i); } } if(f==1)break; } } int main() { char str[1001]; int t; memset(map,0,sizeof(map)); memset(mark,0,sizeof(mark)); f=0; while(gets(str)) { if(str[0]=='0') { f=0; bfs(1); if(f==1){printf("Yes.\n");f=2;} else {printf("No.\n");f=2;} memset(mark,0,sizeof(mark)); memset(map,0,sizeof(map)); } if(f!=2)//如果此时str=“0”就不需要执行这一步; { t=strlen(str); map[str[0]-'a'][str[t-1]-'a']=1; } } return 0; }
相关文章推荐
- hdu 1181 (搜索BFS,深搜DFS,并查集)
- hdu 1181 (搜索BFS,深搜DFS,并查集)
- HDU 1044 Collect More Jewels(搜索,先bfs再dfs)
- HDU 1372 Knight Moves (搜索 使用 dfs bfs两种实现)
- HDU 2181 哈密顿绕行世界问题( 搜索水题bfs+dfs)
- 搜索专题(DFS&&BFS&&剪枝)HDU 1728-逃离迷宫
- hdu 4771 Stealing Harry Potter's Precious (2013亚洲区杭州现场赛)(搜索 bfs + dfs) 带权值的路径
- hdu 1312 Red and Black DFS搜索 or BFS搜索
- [HDU 2102] A计划(搜索题,典型dfs or bfs)
- HDU 1254 推箱子 (搜索中套搜索,BFS + DFS 这感觉,酸爽!)
- HDU - 1198Farm Irrigation (BFS|DFS|并查集)
- hdu 1181 变形课 (dfs)简单搜索
- HDU 1312 Red and Black(经典搜索,DFS&BFS三种方式)
- hdu 1254 推箱子(嵌套搜索,bfs中有dfs)
- hdu 1181 变形课 (dfs)简单搜索
- HDU 1181.变形课【DFS(BFS也可以的)】【问题的转化】【8月5】
- HDU 1312 Red and Black 红与黑 搜索 dfs bfs
- HDU 1312Red and Black(简单搜索 bfs或dfs)
- hdu 1181 变形课 (dfs- -)
- PAT 数据结构 05-图1. List Components (25) 深度搜索DFS和广度搜索BFS