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. 问答项目---账号密码异步校验后进行PHP校验

    在做登陆的时候,通过异步校验后还需要通过PHP来校验账号和密码的正确性. PHP校验账号密码: public function login(){ if(!IS_POST){echo "页面不 ...

  2. 【转载】keil(MDK-ARM)的调试使用

    现在软件的模拟功能都是非常强大,但是有时候会用不好. 原文地址: 那就看这里吧:http://www.cnblogs.com/strongerHuang/p/5596355.html 1.编译+调试 ...

  3. apache+tomcat实现session共享

    apache+tomcat上篇文章,实现了负载均衡,现在我们实现session共享 一.tomcat集群配置,session 同步配置: tomcat1配置  A.修改Engine节点信息: < ...

  4. 组织机构代码校验码生成算法(C#版)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. apache代理weblogic集群办法

    方法一: --关闭iptables和selinux --在apache配置文件httpd.conf最下面添加如下语句,然后重启apache: ServerName 127.0.0.1:80 NameV ...

  6. 配置oem

    [oracle@kaifai ~]$ export ORACLE_SID=dbking[oracle@kaifai ~]$ export ORACLE_SID=kaifai[oracle@kaifai ...

  7. D2 Magic Powder -1/- 2---cf#350D2(二分)

    题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...

  8. 少走冤枉路!带你走过SNMP的那些坑

    SNMP(Simple Network Management Protocol)即简单网络管理协议,是在网络与系统监控领域中,最常使用的一种数据采集技术.尽管这个协议非常简单,但在大规模IT环境监测中 ...

  9. django如何防止csrf(跨站请求伪造)

    什么是CSRF 下面这张图片说明了CSRF的攻击原理: Django中如何防范CSRF Django使用专门的中间件(CsrfMiddleware)来进行CSRF防护.具体的原理如下: 1.它修改当前 ...

  10. PROPAGATION_REQUIRES_NEW VS PROPAGATION_NESTED

    PROPAGATION_REQUIRES_NEW, in contrast to PROPAGATION_REQUIRED, uses a completely independent transac ...