题目链接: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. mongodb数据导入导出mongoexport/mongoimport

    数据导出 mongoexport 假设库里有一张user表,里面有2条记录,我们要将它导出 > use my_mongodb switched to db my_mongodb > db. ...

  2. 入门系列之在Ubuntu上使用Netdata设置实时性能监控

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由小翼 发表于云+社区专栏 介绍 Netdata通过可扩展的Web仪表板提供准确的性能监控,可以显示Linux系统上的流程和服务.它监控 ...

  3. 2017年12月17日 ASP.NET 12个表单元素&&简单控件/复合控件

    12个表单元素可以分为三大类 第一类:文本类 <input type = "text" /> //普通文本框 <input type = "passwo ...

  4. .net IoC 之 Spring.Net 适合刚开始使用

    Spring.Net包括控制反转(IoC) 和面向切面(AOP),这篇文章主要说下IoC方面的入门. 一.首先建立一个MVC项目名称叫SpringDemo,然后用NuGet下载spring(我用的是S ...

  5. 添加jquery脚本文件

    对于后台添加JQuery需要加上../js {insert_scripts files ="../js/jquery.1.14.min.js"}

  6. 流畅的python和cookbook学习笔记(六)

    1.同时迭代多个序列(zip(函数)) 使用zip()函数可以同时迭代多个序列. >>> X = [1, 2, 3, 4, 5, 6] >>> Y = [121, ...

  7. DIV固定宽度和动态拉伸混合水平排列

    1.效果图 2.源代码 html <h2>1.头部固定,尾部拉伸</h2> <div class="container" id="div1& ...

  8. cygwin 的安装和配置

         Cygwin是一个在windows平台上运行的类UNIX模拟环境,是cygnus solutions公司开发的自由软件(该公司开发的著名工具还有eCos,不过现已被Redhat收购).它对于 ...

  9. 基于easyUI实现权限管理系统(三)——角色管理

    此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 相关文件介绍 1. role.jsp:角色管理界面 <!DOCTYPE html PUBLIC "-//W3 ...

  10. centos jdk8 install

    0. 装了好多遍jdk 以前一直是 vi /etc/profile文件 追加 环境变量 ,仔细一看 profile文件提示 尽量不要修改!!! so... 1. 下载jdk8.tar.gz 2. 卸载 ...