Codeforces 793B Igor and his way to work 题解
来源:互联网 发布:orange pi淘宝 编辑:程序博客网 时间:2024/06/05 09:37
题意
给定一个n*m的地图,’S’为起点,’T’为终点,’.’为空地,’*’为路障,问是否存在一条从起点到终点拐弯次数不超过2的路
思路
记忆化搜索,记录4维数据,包括行、列、拐弯次数、方向
代码
#include <cstdio>#include <iostream>using namespace std;char mp[1001][1001];int x1,y1,x2,y2;int f,n,m;int vis[1001][1001][3][5];void dfs(int x,int y,int turn,int d){ if(x<0||x>=n||y<0||y>=m||turn>2||vis[x][y][turn][d]==1||mp[x][y]=='*'||f==1) return; vis[x][y][turn][d]=1; if(x==x2&&y==y2) { f=1; return; } if(d==0||d==1) dfs(x-1,y,turn,1); else if(d==3||d==4) dfs(x-1,y,turn+1,1); if(d==0||d==2) dfs(x+1,y,turn,2); else if(d==3||d==4) dfs(x+1,y,turn+1,2); if(d==0||d==3) dfs(x,y-1,turn,3); else if(d==1||d==2) dfs(x,y-1,turn+1,3); if(d==0||d==4) dfs(x,y+1,turn,4); else if(d==1||d==2) dfs(x,y+1,turn+1,4);}int main(){ cin>>n>>m; for(int i=0;i<n;i++) cin>>mp[i]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(mp[i][j]=='S') { x1=i; y1=j; } else if(mp[i][j]=='T') { x2=i; y2=j; } dfs(x1,y1,0,0); if(f==1) printf("YES\n"); else printf("NO\n"); return 0;}
0 0
- Codeforces 793B Igor and his way to work 题解
- Codeforces 793B Igor and his way to work dfs
- codeforces Igor and his way to work
- B. Igor and his way to work
- B. Igor and his way to work
- B. Igor and his way to work
- codeforce 793 B Igor and his way to work
- Igor and his way to work-Codeforce 793B BFS
- Codeforces 793B Igor and his way to work (dfs/bfs
- Tinkoff B. Igor and his way to work(BFS)
- codeforces B. Igor and his way to work dfs or bfs
- Codeforces-739B:Igor and his way to work(BFS+优化)
- Codeforces 793b B. Igor and his way to work 觉得大神写的3维bfs太复杂,突然发现这题是连连看算法。
- CF-Tinkoff Challenge-Elimination Round-B-Igor and his way to work
- CF793B:B Igor and his way to work(DFS & BFS)
- BFS--cf793b Igor and his way to work
- 【codeforces 776B】Sherlock and his girlfriend
- Codeforces 776B-Sherlock and his girlfriend
- atexit()函数调用注册的顺序
- 复数类计算(多种运算符重载)
- 数据结构之二叉树
- make Unknown module(s) in QT: quick
- Linux 下配置java环境
- Codeforces 793B Igor and his way to work 题解
- NB5.5源代码分析之服务端生成
- 数据结构与算法---起泡排序
- vb.net 教程 3-4 窗体编程 公共控件5 LinkLabel
- pandas的基本用法(一)——数据定义及使用
- leetCode---Container With Most Water
- Lombok的介绍和使用
- Linux下的FILE*与fd
- 多个URL请求Handler里面不同的方法