codeforces 793B. Igor and his way to work
B. Igor and his way to work
3 seconds
256 megabytes
standard input
standard output
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.
Bankopolis looks like a grid of n rows and m columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.
The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid.
Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell;
- "*" — a cell with road works;
- "S" — the cell where Igor's home is located;
- "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each.
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
5 5
..S..
****.
T....
****.
.....
YES
5 5
S....
****.
.....
.****
..T..
#include<bits/stdc++.h>
using namespace std; const int Max = ;
char f[Max][Max];
int d[Max][Max];
int m,n; int fuck(int x,int y,int v)
{
int i=x+;int j=y;
while(i<m&&d[i][j]==-&&f[i][j]!='*') d[i++][j]=v;
i=x-;j=y;
while(i>=&&d[i][j]==-&&f[i][j]!='*') d[i--][j]=v;
i=x;j=y+;
while(j<n&&d[i][j]==-&&f[i][j]!='*') d[i][j++]=v;
i=x;j=y-;
while(j>=&&d[i][j]==-&&f[i][j]!='*') d[i][j--]=v;
} int main()
{
ios_base::sync_with_stdio();
int i,j;
cin>>m>>n;
memset(d, -, Max*Max*sizeof(int));
for(i=;i<m;i++) for(j=;j<n;j++) cin>>f[i][j];
for(i=;i<m;i++) for(j=;j<n;j++) if(f[i][j]=='S'){
d[i][j]=;
//cout<<i<<j;
fuck(i,j,);
}
for(i=;i<m;i++) for(j=;j<n;j++) if(d[i][j]==){
fuck(i,j,);}
for(i=;i<m;i++) for(j=;j<n;j++) if(d[i][j]==){
fuck(i,j,);}
for(i=;i<m;i++) for(j=;j<n;j++) if(f[i][j]=='T'){
cout<<(d[i][j]==-?"NO":"YES");}
return ;
}
codeforces 793B. Igor and his way to work的更多相关文章
- codeforces 793B - Igor and his way to work(dfs、bfs)
题目链接:http://codeforces.com/problemset/problem/793/B 题目大意:告诉你起点和终点,要求你在只能转弯两次的情况下能不能到达终点.能就输出“YES”,不能 ...
- 【codeforces 793B】Igor and his way to work
[题目链接]:http://codeforces.com/contest/793/problem/B [题意] 给一个n*m大小的方格; 有一些方格可以走,一些不能走; 然后问你从起点到终点,能不能在 ...
- codeforces 598D Igor In the Museum
题目链接:http://codeforces.com/problemset/problem/598/D 题目分类:dfs 题目分析:处理的时候一次处理一片而不是一个,不然会超时 代码: #includ ...
- Codeforces 747F Igor and Interesting Numbers DP 组合数
题意:给你一个数n和t,问字母出现次数不超过t,第n小的16进制数是多少. 思路:容易联想到数位DP, 然而并不是...我们需要知道有多少位,在知道有多少位之后,用试填法找出答案.我们设dp[i][j ...
- 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 ...
- Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- 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 ...
- [BFS]Codeforces Igor In the Museum
Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- [02] Spring主要功能模块概述
1.Spring主要功能模块 1.1 Core Container Spring的核心容器模块,其中包括: Beans Core Context SpEL Beans和Core模块,是框架的基础部 ...
- sqlserver 发送http请求
sp_configure 'show advanced options', 1; GO RECONFIGURE; GO sp_configure 'Ole Automation Procedures' ...
- java异步编程降低延迟
目录 java异步编程降低延迟 一.ExecutorService和CompletionService 二.CompletableFuture(重要) 三.stream中的parallel(并行流) ...
- How to Enable TLS 1.2 on Windows Server 2008 R2 and IIS 7.5
Nowadays there is an SSL vulnerability called POODLE discovered by Google team in SSLv3 protocol. So ...
- 在平衡树的海洋中畅游(四)——FHQ Treap
Preface 关于那些比较基础的平衡树我想我之前已经介绍的已经挺多了. 但是像Treap,Splay这样的旋转平衡树码亮太大,而像替罪羊树这样的重量平衡树却没有什么实际意义. 然而类似于SBT,AV ...
- 使用xshell连接服务器,数字键盘无法使用解决办法
打开会话管理器,选中需要设置的服务器连接,右键->属性 选中 终端->VT模式->初始数字键盘模式->设为普通 保存,重新连接即可.
- 使用Hexo+Github搭建属于自己的博客(进阶)
主题的配置:这里以NexT主题作为题材 1.安装NexT,在其文件夹中鼠标右键,点击Git Base Here.输入命令:git clone https://github.com/iissnan/he ...
- 剑指offer:二叉树中和为某一值的路径
本来这只是一个普通的算法题,但是当初自己OJ上提交时,总是提交失败,而我自己认定程序逻辑没有任何问题.然后开始就在本机上调试,结果发现这是由于Python的对象机制而引发的.所以先把问题算法题贴出来, ...
- mysql 多列索引的生效规则,生成1000w数据的存储过程
https://www.cnblogs.com/codeAB/p/6387148.html
- 21035218_Linux 实验三 程序破解
20135218 姬梦馨 1:掌握NOP.JNE.JE.JMP.CMP的汇编指令的机器码. NOP:NOP指令即“空指令”.执行到NOP指令时,CPU什么也不做,仅仅当做一个指令执行过去并继续执行N ...