题目链接:codeforces793 B. Igor and his way to work (dfs)

求从起点到终点转方向不超过两次是否有解,,好水啊,感觉自己代码好搓。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<limits.h>
#define CLR(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long ll;
const int N = ;
int n, m;
int sx, sy, ex, ey;int flag;
char s[N][N];
int vis[N][N][][];
void dfs(int x, int y, int d, int turn) {//上下:d = 1,左右:d = 2
if(turn > || vis[x][y][d][turn]) return;
if(x == ex && y == ey) {
flag = true;
return;
}
vis[x][y][d][turn] = ;
if(x- >= && s[x-][y] != '*' && !vis[x-][y][][turn+(d==)]) {
dfs(x-, y, , turn + (d==));
}
if(x+ < n && s[x+][y] != '*' && !vis[x+][y][][turn+(d==)]) {
dfs(x+, y, , turn + (d==));
}
if(y- >= && s[x][y-] != '*' && !vis[x][y-][][turn+(d==)]) {
dfs(x, y-, , turn + (d==));
}
if(y+ < m && s[x][y+] != '*' && !vis[x][y+][][turn+(d==)]) {
dfs(x, y+, , turn + (d==));
}
}
int main() {
int i, j;
scanf("%d%d ", &n, &m);
for(i = ; i < n; ++i) {
scanf("%s", s[i]);
for(j = ; j < m; ++j) {
if(s[i][j] == 'S') {sx = i; sy = j;}
else if(s[i][j] == 'T') {ex = i; ey = j;}
}
}
flag = ;
CLR(vis, );
dfs(sx, sy, , );
if(flag) puts("YES");
else puts("NO");
return ;
}

codeforces793 B. Igor and his way to work (dfs)的更多相关文章

  1. codeforces 793B - Igor and his way to work(dfs、bfs)

    题目链接:http://codeforces.com/problemset/problem/793/B 题目大意:告诉你起点和终点,要求你在只能转弯两次的情况下能不能到达终点.能就输出“YES”,不能 ...

  2. Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集

    D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...

  3. Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)

    D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. codeforces 793B. Igor and his way to work

    B. Igor and his way to work time limit per test 3 seconds memory limit per test 256 megabytes input ...

  5. 【CodeForces - 598D】Igor In the Museum(bfs)

    Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...

  6. Codeforces 598D:Igor In the Museum

    D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. [BFS]Codeforces Igor In the Museum

     Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. F. Igor and Interesting Numbers

    http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道 ...

  9. Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)

    题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...

随机推荐

  1. JavaScript弹出层

    1.这个弹出层就是一个DIV 2.看需要什么效果 2.1.如果是仅仅需要弹出层,而背后的网页同样可以点击,那么只需要一个DIV即可,效果如图: 2.2.需要一层透明背景,而后面的网页只能看不能点,效果 ...

  2. view向全屏延伸时的属性设置

    从iOS7 开始,当视图被navigationbar和tabbar包裹时,view默认会延伸到状态bar下面, 1.如果要让view贴着上下的状态bar展示,可以在viewDidLoad中设置属性 s ...

  3. 深入理解JavaScript系列(40):设计模式之组合模式

    介绍 组合模式(Composite)将对象组合成树形结构以表示“部分-整体”的层次结构,组合模式使得用户对单个对象和组合对象的使用具有一致性. 常见的场景有asp.net里的控件机制(即control ...

  4. 清除SQL Server内存

    数据库进行查询时,会缓存结果集,当查询结果过大时会出现内存爆满的情况,如果手动清除SQL所占用的内存呢,在网上搜索一下,把结果贴下面: --强制释放内存 Create procedure [dbo]. ...

  5. 巧用CheckedTextView完成自定义radiobutton的listview

    因为要用自定义图片的radiobutton的listview,最开始想自己重新写BaseAdapter,重新定义BaseAdapter中的每个list的item.总之android提供了太多方便的控件 ...

  6. JavaScript call 和apply 的理解

    这两个方法对于一些新手而言难耐弄清他们到底是怎么回事,对我我来讲我对call和apply的方法理解的也比较含糊.今天闲来无事准备彻底搞call和apply到底是怎么回事.本着互联网分享精神.我将我自己 ...

  7. MVC 下拉框联动效果(单选)

    下拉框联动效果,我们以部门--职位为例,选择部门时,关联到该部门的职位.下拉框的写法就不多说了,详细请参照前文. 视图: 其中,dept是部门的属性,deptlist是部门下拉框的属性,job是职位的 ...

  8. js实现栈

    栈是一种先进后出的特殊线性表结构,存储上分链式存储和顺序存储两种方式 链式存储: function LinkedStack() { let Node = function (ele) { this.e ...

  9. Servlet开发(三)之ServletConfig,ServletContext

    1. ServletConfig Servlet是开发动态web的技术,而web.xml是Tomcat工程中最基础也最重要的配置文件,Tomcat启动项目的时候会加载并读取这个文件,其中web.xml ...

  10. CSS实现响应式布局(自动拆分几列)

    1.css代码 <style type="text/css"> .container{ margin-top: 10px; } .outerDiv{ float:lef ...