【codeforces 793B】Igor and his way to work
【题目链接】: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的更多相关文章
- 【Codeforces 598D】Igor In the Museum
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 同一个联通块里面答案都一样. 把每个联通块的答案都算出来 然后赋值就好 [代码] #include <bits/stdc++.h> ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【30.43%】【codeforces 746C】Tram
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- jQuery - 选中复选框则弹出提示框
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 包含utf8字符的 pickle 转 json的大坑处理过程
背景:希望将pickle转换为json,由于pickle里有utf8的字符,因此转换失败. 转换代码如下: ''' Convert a pkl file into json file ''' impo ...
- 洛谷P3808 & P3796 AC自动机模板
题目:P3808:https://www.luogu.org/problemnew/show/P3808 P3796:https://www.luogu.org/problemnew/show/P37 ...
- Java-java-com-util-common-service:ServiceException.java
ylbtech-Java-java-com-util-common-service:ServiceException.java 1.返回顶部 1. package com.shineyoo.manag ...
- lodop使用
根据相应的操作系统,安装install_lodop32.exe文件,它里面包含两个exe文件install_lodop32.exe和install_lodop64.exe,在页面的头部中引入: < ...
- bzoj1588: [HNOI2002]营业额统计(权值线段树)
1588: [HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 16863 Solved: 6789[Submit][Sta ...
- [Apple开发者帐户帮助]六、配置应用服务(2)创建DeviceCheck私钥
要验证与DeviceCheck服务的通信,您将使用启用了DeviceCheck的私钥. 首先创建并下载启用了DeviceCheck 的私钥.然后获取密钥标识符(kid)以创建JSON Web令牌(JW ...
- Scala学习1————scala开发环境搭建(windows 10)
Scala开发环境搭建 先讲几点我学习scala的目的或者原因吧: JVM在企业中的霸主地位,Scala也是JVM上的语言,很有可能未来会从Java过度到Scala也不是不可能. 先进的函数式编程和面 ...
- ROS-URDF-活动关节
前言:介绍活动关节,并使机器人活动起来. 参考自:http://wiki.ros.org/urdf/Tutorials/Building%20a%20Movable%20Robot%20Model%2 ...
- 35个jquery小技巧
1. 禁止右键点击 ? 1 2 3 4 5 $(document).ready(function(){ $(document).bind("contextmenu",fun ...