【题目链接】:http://codeforces.com/contest/793/problem/B

【题意】



给一个n*m大小的方格;

有一些方格可以走,一些不能走;

然后问你从起点到终点,能不能在转弯次数不超过2的情况下达到;

【题解】



记忆化搜索写一个;

f[x][y][z]表示,到了x,y这个坐标,当前方向是z的最小转弯次数;

按照这个数组;

写一个dfs就好;

不会难.



【Number Of WA】



2(一开始没加第三维TAT)



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,0,-1,0,-1,-1,1,1};
const int dy[9] = {0,0,-1,0,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e3+100; int n,m,a[N][N],x0,y0,x1,y1,f[N][N][5];
char s[N]; void dfs(int x,int y,int pre,int num)
{
if (a[x][y]==0) return;
if (num>2) return;
if (f[x][y][pre]!=-1 && f[x][y][pre]<=num) return; f[x][y][pre] = num;
rep1(i,1,4)
{
int tx = x+dx[i],ty = y + dy[i];
int before = pre+2;
if (before>4) before-=4;
if (pre!=0 && i==before) continue;
if (pre==0)
dfs(tx,ty,i,num);
else
{
if (pre!=i)
dfs(tx,ty,i,num+1);
else
dfs(tx,ty,i,num);
}
}
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n >> m;
rep1(i,1,n)
{
cin>>(s+1);
rep1(j,1,m)
if (s[j]=='*')
a[i][j] = 0;
else
{
a[i][j] = 1;
if (s[j]=='S')
x0= i,y0=j;
if (s[j]=='T')
x1 =i,y1 = j;
}
}
ms(f,255);
dfs(x0,y0,0,0);
rep1(i,1,4)
if (f[x1][y1][i]!=-1)
return cout <<"YES"<<endl,0;
cout <<"NO"<<endl;
return 0;
}

【codeforces 793B】Igor and his way to work的更多相关文章

  1. 【Codeforces 598D】Igor In the Museum

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 同一个联通块里面答案都一样. 把每个联通块的答案都算出来 然后赋值就好 [代码] #include <bits/stdc++.h> ...

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

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

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. 好记性不如烂笔头——DML/DDL/DCL/TCL,OLTP/OLAP

    DML:数据操作语言,就是增删改之类的语句 DDL:数据定义语言,创建.修改.删除表等 ALTER 语句 (Transact-SQL) CREATE 语句 (Transact-SQL) DISABLE ...

  2. 时序数据库深入浅出之存储篇——本质LSMtree,同时 metric(比如温度)+tags 分片

    什么是时序数据库 先来介绍什么是时序数据.时序数据是基于时间的一系列的数据.在有时间的坐标中将这些数据点连成线,往过去看可以做成多纬度报表,揭示其趋势性.规律性.异常性:往未来看可以做大数据分析,机器 ...

  3. B1922 [Sdoi2010]大陆争霸 最短路

    我一直都不会dij的堆优化,今天搞了一下...就是先弄一个优先队列,存每个点的数据,然后这个题就加了一点不一样的东西,每次的最短路算两次,一次是自己的最短路,另一次是机关的最短路,两者取最大值才是该点 ...

  4. Principal Component Analysis ---- PRML读书笔记

    To summarize, principal component analysis involves evaluating the mean x and the covariance matrix ...

  5. MySQL SQL优化教程

    转自:https://www.cnblogs.com/duanxz/archive/2013/02/01/2889413.html 一,查询SQL执行效率 通过show status命令了解各种SQL ...

  6. 第2章 安装Nodejs 2-4 Linux下安装Nodejs

    linux下编译安装Nodejs  GCC和G++分别是GNU的C和C++编译器.它们在执行编译工作的时候把源代码通过预处理转化成汇编语言生成.i后缀的文件,再由汇编变成目标机器代码,最后连接目标代码 ...

  7. C语言程序创建文件夹

    #include <stdio.h> #include <process.h> #include <dir.h> int main(void) { int stat ...

  8. 浅讲ajax

    1.ajax入门案例 1.1 搭建Web环境 ajax对于各位来说,应该都不陌生,正因为ajax的产生,导致前台页面和服务器之间的数据传输变得非常容易,同时还可以实现页面的局部刷新.通过在后台与服务器 ...

  9. [BZOJ1821][JSOI2010]部落划分

    感觉学了这么久还是有那么一丢丢进步的...上个学期看到这道题,虽然早就学过并查集和二分了但还是一点思路都没有,现在可以秒切了呢 思路就是二分+并查集,有些人说是生成树,其实它没有变成树,只是运用了生成 ...

  10. 【转载】cocos2dx 中 Android NDK 加载动态库的问题

     原文地址:http://blog.csdn.net/sozell/article/details/10551309 cocos2dx 中 Android NDK 加载动态库的问题 闲聊 最近在接入各 ...