http://codeforces.com/contest/793/problem/B

题意:
一个地图,有起点和终点还有障碍点,求从起点出发到达终点,经过的路径上转弯次数是否能不超过2。

思路:

直接dfs,但是要优化一下,用vis[x][y][dir]来记录在(x,y)并且方向为dir时的最少转弯数,这样在dfs的时候可以剪掉一些不符合的情况。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const int maxn=+; int n,m;
int sx,sy;
int flag;
char g[maxn][maxn];
int vis[maxn][maxn][]; int dx[]={,,,-};
int dy[]={,-,,}; void dfs(int x,int y,int dir,int turn)
{
if(flag) return;
if(turn>) return;
if(vis[x][y][dir]<=turn) return; //优化
if(g[x][y]=='T')
{
if(turn<=) flag=;
return;
}
vis[x][y][dir]=turn;
for(int k=;k<;k++)
{
int xx=x+dx[k];
int yy=y+dy[k];
if(g[xx][yy]=='*') continue;
if(xx<||x>=n||yy<||yy>=m) continue;
if(k!=dir) dfs(xx,yy,k,turn+);
else dfs(xx,yy,k,turn);
}
} int main()
{
//freopen("D:\\input.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
int ff=;
for(int i=;i<n;i++)
{
scanf("%s",g[i]);
if(!ff)
for(int j=;j<m;j++)
if(g[i][j]=='S') {sx=i;sy=j;ff=;}
}
flag=;
memset(vis,inf,sizeof(vis));
for(int k=;k<;k++)
{
int x=sx+dx[k];
int y=sy+dy[k];
if(x<||x>=n||y<||y>=m) continue;
if(g[x][y]!='*') dfs(x,y,k,);
}
if(flag) puts("YES");
else puts("NO");
}
return ;
}

Tinkoff Challenge - Elimination Round B. Igor and his way to work(dfs+优化)的更多相关文章

  1. Tinkoff Challenge - Elimination Round 开始补题

    A. Oleg and shares time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Tinkoff Challenge - Elimination Round D. Presents in Bankopolis(区间DP)

    http://codeforces.com/contest/793/problem/D 题意:给出一些点和他们之间的距离,是有向的,这些点从1~n顺序排列,现在选出k个点组成一条路径,使他们之间的距离 ...

  3. Tinkoff Challenge - Elimination Round C. Mice problem(模拟)

    传送门 题意 给出一个矩形的左下角和右上角的坐标,给出n个点的初始坐标和运动速度和方向,询问是否存在一个时间使得所有点都在矩形内,有则输出最短时间,否则输出-1 分析 对于每个点如果运动过程中都不在矩 ...

  4. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) 继续跪一把

    这次的前三题挺简单的,可是我做的不快也不对. A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megab ...

  5. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2)

    A: 思路:就是找b,c之前有多个s[i] 代码: #include<stdio.h>#define ll long longusing namespace std;ll a,b,c;in ...

  6. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  7. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  9. 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C

    http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...

随机推荐

  1. 【黑金ZYNQ7000系列原创视频教程】07.自定义IP——定制RTC IP实验

    黑金论坛地址: http://www.heijin.org/forum.php?mod=viewthread&tid=36641&extra=page%3D1 爱奇艺地址: http: ...

  2. 关于wcf三大工具的使用(wsdl.exe svcutil.exe disco.exe)

    首先,我们必须创建一个wcf服务.并部署到IIS中.这里我已经将一个StudentService服务部署到我自己的电脑了. (1)svcutil.exe svcutil.exe工具的作用是通过服务地址 ...

  3. java GC工作机制

    转自:http://www.cnblogs.com/hzdtf/articles/5419987.html GC:垃圾回收站,是将java的无用的堆对象进行清理,释放内存,以免发生内存泄露.在介绍ja ...

  4. Floyd求字典序最小的路径

    hdu1384 Minimum Transport Cost Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. linux注意的一些地方

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行 #include <assert.h>void assert( int expr ...

  6. [Jenkins] 批量删除构建历史

    Manage Jenkins -> Script Console def jobName = "Some_Job_Name" def maxNumber = 64 Jenki ...

  7. CentOS7 部署tomcat

    一.环境说明: 在 CentOS7下面部署tomcat7 . 二.tomcat部署 1.新建tomcat目录  mkdir tomcat 2.上传tomcat 安装文件   apache-tomcat ...

  8. js 格式验证大全

    1.身份证号码验证: var Common = { //身份证号验证 IsIdCardNo: function (IdCard) { var reg = /^\d{15}(\d{2}[0-9X])?$ ...

  9. lampp and testrail

    https://wyzx.testrail.net szllq2000 http://129.0.1.228/testrail/ http://docs.gurock.com/testrail-adm ...

  10. php curl采集数据问题汇总

    1. 使用curl获取网页数据提示: "curl: (6) Could not resolve host: xxx.xxx.com ; Name or service not known&q ...