题目链接: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. JPA为字段设置默认值

    http://blog.csdn.net/u011983531/article/details/51286839 在使用JPA时,如果需要为属性设置默认值,很自然的,你可能会想到用下面的方式. @Co ...

  2. JQuery JSON Servlet

    <script type="text/javascript" src="js/jquery-1.10.2.js"></script> & ...

  3. Maven 常见知识点整理

    认识 Maven Maven 的作用? 1.添加第三方jar包 2.解决jar包之间的依赖关系 3.获取第三方jar包 4.将项目拆成多个工程模块 Maven 是什么? 是Apache软件基金会组织维 ...

  4. step1: python & scrapy安装

    #首先安装python,这里安装python所需依赖包yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-dev ...

  5. java.lang.RuntimeException Unable to instantiate application Caused by: java

    参考:http://blog.csdn.net/xufazhong/article/details/71155528 dependencies { classpath 'com.android.too ...

  6. 【分布式消息队列-MQ】

    http://www.cnblogs.com/itfly8/p/5155983.html

  7. aspose.word 读取word段落内容

    注:转载请标明文章原始出处及作者信息 aspose.word 插件下载 链接: http://pan.baidu.com/s/1qXIgOXY 密码: wsj2 使用原因:无需安装office,无兼容 ...

  8. Java基础(四)方法和数组

    一.方法 1.方法的定义 方法也叫函数,就是一个能独立完成某个功能的一段代码.方法可以看作一个整体. 语法: 修饰符 返回类型 方法名字(数据类型 变量名,数据类型 变量名,……[形式参数(0个到n个 ...

  9. OkHttp完全解析之整体调用流程

    前言:阅读好的代码如同观赏美景一样的美妙 OkHttp是一个Square公司在github开源的Java网络请求框架,非常流行.OkHttp 的代码并不是特别庞大,代码很多巧妙的实现,非常值得学习. ...

  10. 反汇编调试Android

    https://code.google.com/p/android/issues/detail?id=73076 http://my.unix-center.net/~Simon_fu/?p=527 ...