题目链接:http://ac.jobdu.com/problem.php?pid=1461

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1461 Tempter of the bone.cpp
// Jobdu
//
// Created by PengFei_Zheng on 24/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#define MAX_SIZE 8 using namespace std; int n, m, t;
char plot[MAX_SIZE][MAX_SIZE];
bool visited[MAX_SIZE][MAX_SIZE]; int change[][]={{,,-,},{-,,,}};//left right up down struct Pos{
int x;
int y;
};
Pos start;
Pos over;
bool flag; void DFS(Pos pos,int time){
Pos nextP;
for(int i = ; i < ; i ++){
nextP.x = pos.x + change[][i];
nextP.y = pos.y + change[][i];
if(nextP.x< || nextP.x>=n || nextP.y< || nextP.y>=m) continue;
if(plot[nextP.x][nextP.y] == 'X' || visited[nextP.x][nextP.y]==true) continue;
if(plot[nextP.x][nextP.y] == 'D'){
if(time+==t){
flag = true;
return;
}
else{
continue;
}
}
visited[nextP.x][nextP.y]=true;
DFS(nextP,time+);
visited[nextP.x][nextP.y]=false;
if(flag==true) return;
} }
int main(){
while(scanf("%d%d%d",&n,&m,&t)!=EOF){ if(==n && ==m && ==t) break;
for(int i = ; i < n ; i++){
scanf("%s",plot[i]);
}
flag = false;
for(int i = ; i < n ; i++){
for(int j = ; j < m ; j++){
visited[i][j]=false; if(plot[i][j]=='S'){
start.x = i;
start.y = j;
}
if(plot[i][j]=='D'){
over.x = i;
over.y = j;
}
}
}
if((start.x+start.y)% == ((over.x+over.y)%+t%) %){
visited[start.x][start.y]=true;
DFS(start,);
}
flag == true ? printf("YES\n") : printf("NO\n");
}
return ;
}
/**************************************************************
Problem: 1461
User: zpfbuaa
Language: C++
Result: Accepted
Time:10 ms
Memory:1520 kb
****************************************************************/

题目1461:Tempter of the bone(深度优先遍历DFS)的更多相关文章

  1. 广度优先遍历-BFS、深度优先遍历-DFS

    广度优先遍历-BFS 广度优先遍历类似与二叉树的层序遍历算法,它的基本思想是:首先访问起始顶点v,接着由v出发,依次访问v的各个未访问的顶点w1 w2 w3....wn,然后再依次访问w1 w2 w3 ...

  2. 图的深度优先遍历(DFS)和广度优先遍历(BFS)

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  3. 图的深度优先遍历DFS

    图的深度优先遍历是树的前序遍历的应用,其实就是一个递归的过程,我们人为的规定一种条件,或者说一种继续遍历下去的判断条件,只要满足我们定义的这种条件,我们就遍历下去,当然,走过的节点必须记录下来,当条件 ...

  4. 图的深度优先遍历(DFS) c++ 非递归实现

    深搜算法对于程序员来讲是必会的基础,不仅要会,更要熟练.ACM竞赛中,深搜也牢牢占据着很重要的一部分.本文用显式栈(非递归)实现了图的深度优先遍历,希望大家可以相互学习. 栈实现的基本思路是将一个节点 ...

  5. ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)

    题意  一仅仅狗要逃离迷宫  能够往上下左右4个方向走  每走一步耗时1s  每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次  问狗是否有可能逃离这个迷宫 直接DFS  直道找到满足条件的路径 ...

  6. 图的深度优先遍历(DFS)—递归算法

    实验环境:win10, DEV C++5.11 实验要求: 实现图的深度优先遍历 实验代码: #include <iostream> #define maxSize 255 #includ ...

  7. 深度优先遍历DFS

    深度优先遍历,这个跟树中的遍历类似,做深度遍历就是访问一个节点之后,在访问这个节点的子节点,依次下去是一个递归的过程. 具体代码: void DFS(MGraph g ,int i) {     in ...

  8. 16.boost图深度优先遍历DFS

    #include <iostream> #include <boost/config.hpp> //图(矩阵实现) #include <boost/graph/adjac ...

  9. 图的深度优先遍历(DFS)和广度优先遍历(BFS)算法分析

    1. 深度优先遍历 深度优先遍历(Depth First Search)的主要思想是: 1.首先以一个未被访问过的顶点作为起始顶点,沿当前顶点的边走到未访问过的顶点: 2.当没有未访问过的顶点时,则回 ...

随机推荐

  1. Intellij MyBatisPlus Plugin插件破解

    1. 下载原始的MyBatisPlus Plugin插件. 2. 下载替换包,请根据实际版本下载: https://github.com/myoss/profile/tree/master/idea/ ...

  2. lvm讲解/磁盘故障小案例

    4.10/4.11/4.12 lvm讲解 4.13 磁盘故障小案例 lvm讲解 磁盘故障小案例

  3. Android四大组件之——Activity的开启:StartActivity()和StartActivityForResult()(图文详解)

                如需转载请在文章开头处注明本博客网址:http://www.cnblogs.com/JohnTsai       联系方式:JohnTsai.Work@gmail.com   ...

  4. Asp.net mvc怎么在razor里写js代码

    我试图在Razor里写JS代码,但是不行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3 ...

  5. ubuntu 4.10~5.10 :古老的ubuntu上安装oracle10g的情况

    64位的: 不用想了,安装不上,因为ubuntu库里没有提供编译环境:安装不上gcc-multilib库.也没有libc6-dev-i386库! 自己这点水平,真搞不定! 32位的: 很顺利.很顺利! ...

  6. 找不到 android-support-v4 解决办法

    Project->properties->Java Build Path->Libraries->Add External Jars中加入sdk目录下的extras/andro ...

  7. crontab修改默认编辑器

    crontab默认编辑器为nano 修改crontab默认编辑器为vi或者其他的编辑器 可以用命令select-editor修改 改为3或者4 再用crontab -e 就是vim打开了

  8. 查询SQL阻塞语句

    SELECT SPID=p.spid, DBName = convert(CHAR(),d.name), ProgramName = program_name, LoginName = convert ...

  9. z-index 层级关系

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  10. SpringMVC -- 梗概--源码--贰--上传

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...