题目链接: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. HTTP协议(二)header标头说明

    HTTP协议(二):header标头说明 Header 解释 示例 Accept-Ranges 表明服务器是否支持指定范围请求及哪种类型的分段请求 Accept-Ranges: bytes Age 从 ...

  2. ASP.NET MVC4 新手入门教程之五 ---5.用控制器访问模型数据

    在本节中,将创建一个新的MoviesController类并编写代码来检索电影数据并将其显示在浏览器中使用一个视图模板. 才走出下一步生成应用程序. 用鼠标右键单击控制器文件夹中并创建一个新的 Mov ...

  3. java 并发 (四) ---- 并发容器

    Hashmap 和 Concurrenthashmap Hashmap 不适合并发,应该使用ConcurrentHashMap . 这是很多人都知道的,但是为什么呢? 可以先看一下这两篇文章. JDK ...

  4. 六、mybatis分页插件集成

    本文基于上一篇“集成mybatis”内容 1.添加依赖 <!-- mybatis-pageHelper --> <dependency> <groupId>com. ...

  5. BBS登录与注册功能

    登录功能 视图函数 def my_login(request): if request.method == 'GET': return render(request, 'login.html') el ...

  6. 文字编辑器FCKeditor 简介以及基本配置和使用方法

    什么是FCKeditor FCKeditor是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器.它志于轻量化,不需要太复杂的安装步骤即可使用.它可和PHP.JavaScript.ASP.ASP ...

  7. FeatureLayer 里属性数据的提取与显示

    我们用工程文件所发布的WebServer下,包含一个个图层,这些图层根据顺序进行了 0 开始的编号,这些就是FeatureLayer的地址了! FeatureLayer 包含了地图的属性信息,十分好用 ...

  8. Windows API 编程----EnumWindows()函数的用法

    1. 函数原型: BOOL WINAPI EnumWindows( _In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam); lpEnumFunc: 应用程序 ...

  9. Codeforces Round #411 (Div. 2) C. Find Amir

    C. Find Amir time limit per test   1 second memory limit per test   256 megabytes   A few years ago ...

  10. linux 系统开机自启执行 操作的配置

    1 linux 服务注册 service文件 在service文件中设置变量和环境变量 [Unit] Description= #服务描述 After=syslog.target #服务启动依赖 [S ...