【题目链接】: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. 洛谷⑨月月赛Round2 官方比赛 OI

    自评: (完成时间3.5时) 第一题 模拟 虽然A了,代码敲得有点慢 第二题 最短路 第一次敲对了,又考虑数据范围和答案范围,改错了,100分改成42分.QAQ. 第三题 乱搞 80分 还可以(因为没 ...

  2. Recommended Settings for Tracing and Message Logging

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/recommended-settings-for-t ...

  3. hdu 2177(威佐夫博奕+打表)

    取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. python 关于文件操作的一些理解

    在用python进行数据处理编程中,往往涉及到文件IO口读写,IO口的读写性能会极大的影响程序的运行时间.在进行文件写入时,一般会存在两种情况.第一种是数据到来马上进行数据写入,即来一条写一条,第二种 ...

  5. css 引入方式

    css介绍 现在的互联网前端分三层: HTML:超文本标记语言.从语义的角度描述页面结构. CSS:层叠样式表.从审美的角度负责页面样式. JS:JavaScript .从交互的角度描述页面行为 CS ...

  6. Windows phone开发 页面布局之屏幕方向

    (博客部分内容参考Windows phone开发文档) Windows phone的屏幕方向是利用Windows phone设备的方向传感器提供的数据实现切换的. Windows Phone支持纵向和 ...

  7. VHDL之FSM

    1 Intro The figure shows the block diagram of a single-phase state machine. The lower section contai ...

  8. sql server 存储过程(事务,带参数声明,数据库瘦身)

    CREATE PROCEDURE procedureName (@var1 as varchar(50),@var2 as varchar(50)) --建立未发临时表 AS begin tran - ...

  9. 3、scala函数入门

    1.定义函数 2.在代码块中定义函数体 3.递归函数与返回类型 4.默认参数 5.带名参数 6.变长参数 7.使用序列调用变长参数  8.过程 9.lazy值              10.异常 1 ...

  10. cannot find Toolkit in /usr/local/cuda-8.0

    对于新版本ubuntukylin17.04安装CUDA时出现 cannot find Toolkit in /usr/local/cuda-8.0 问题 尝试了各种方法,均不妥当...... 参考:h ...