【题目链接】: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. hdoj Radar Installation

    Problem Description Assume the coasting is an infinite straight line. Land is in one side of coastin ...

  2. [Apple开发者帐户帮助]一、开始(2)登录您的开发者帐户

    使用Apple ID登录您的开发者帐户.如果您注册了付费程序(Apple Developer Program或Apple Developer Enterprise Program),请使用您用于注册的 ...

  3. selenium3 + python - select定位

    一.Select模块(index)     1.导入Select模块.直接根据属性或索引定位     2.先要导入select方法:from selenium.webdriver.support.se ...

  4. python 46 盒模型 与盒模型布局

    一:盒模型 1.  盒模型的概念 广义盒模型:文档中所有功能性及内容性标签,及文档中显示性标签 侠义盒模型:文档中以块级形式存在的标签(块级标签拥有盒模型100%特性且最常用) 盒模型组成:margi ...

  5. rancher导入k8s集群后添加监控无数据

    1.日志报错 rancher导入k8s集群后添加监控无数据,rancher日志报错: k8s.io/kube-state-metrics/pkg/collectors/builder.go:: Fai ...

  6. gitlab克隆报错:remote: HTTP Basic: Access denied;remote: You must use a personal access token with ‘api’ scope for Git over HTTP.

    错误: remote: HTTP Basic: Access denied remote: You must use a personal access token with ‘api’ scope ...

  7. MSSQL:查看作业情况

    select j.name 'Job名',        j.description '描述',        j.ENABLED job_enabled,        cast(js.last_r ...

  8. 基于NPOI的扩展

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.HSS ...

  9. 5.26 Quartz任务调度图解

  10. 5.13Junit单元测试-反射-注解

    一.Junit单元测试 * 测试分类: 1.黑盒测试:不需要写代码,给输入值,看程序是否能够输出期望的值 2.白盒测试:需要些代码的.关注程序具体的执行流程 Junit使用:白盒测试 步骤: 1.定义 ...