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 ...
随机推荐
- IDEA 创建和使用tomcat
一.创建一个普通web项目,步骤略,如下图. 二.配置项目相关信息. 1.通过如下方式在Artifacts下添加我们的项目. 2.选中我们的项目. 3.修改项目的默认输出位置,可根据需要修改. 4.如 ...
- ASP.NET Core读取AppSettings (转载)
今天在把之前一个ASP.NET MVC5的Demo项目重写成ASP.NET Core,发现原先我们一直用的ConfigurationManager.AppSettings[]读取Web.config中 ...
- 【LeetCode105】Construct Binary Tree from Preorder and Inorder Traversal★★
1.题目 2.思路 3.java代码 //测试 public class BuildTreeUsingInorderAndPreorder { public static void main(Stri ...
- 利用数据库触发器让字段与自增长Id相关联
十年河东,十年河西,莫欺少年穷 学无止境,精益求精 今天是数据库脚本类的代码,所以不想过多阐述 如下数据表: create table Card( Id ,) primary key, CardNo ...
- VS2017登陆不了,TFS无法连接成功的问题
由于使用的win7 64位操作系统,重装系统以后,安装了vs2017,登陆不成功,https://auth.gfx.ms/16.000.27887.2/OldConvergedLogin_PCore. ...
- Linux常用指令【转载】
[收藏]Linux常用指令[转载] $ 命令行提示符 粗体表示命令 斜体表示参数 filename, file1, file2 都是文件名.有时文件名有后缀,比如file.zip command 命令 ...
- 个人作业Week3
个人作业week3 一. 调研,评测 1.我的使用体验 版本:IOS版 BUG_1: 点击单词本中的“同步”后,会提示登录Microsoft账户.登录成功立即开始同步单词本.在单词本同步过程中, ...
- 同步手绘板——json
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族 ...
- <构建之法>13-17
13章软件测试. 从基本名词到软件测试的分类方法,啃完这15页书,至少对与软件测试的理解程度不是停留在以前的层次(让用户使用,然后提出碰到什么问题) 测试不是那么简单就阐述的完全.测试按测试目的分类可 ...
- 广商博客沖刺第一天(new ver):
項目名稱:廣商博客 沖刺二天傳送門 此次Sprint的目标:全部sprint任務完成 时间:1星期左右 每日立会 Daily Standup Meeting: 1#A3008 晚上8点开始,大概1小时 ...