题目链接: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. [mysql]ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

    From: http://m.blog.csdn.net/blog/langkeziju/13511411 我的MySQL版本为5.6.14版本,是二进制包安装的(虽然是二进制包安装的,但是以下问题同 ...

  2. PHP替换回车换行的三种方法

    一个小小的换行,其实在不同的平台有着不同的实现,为什么要这样,世界是多样的! 本来在Unix世界换行用/n来代替换行, Windows为了体现不同,就用/r/n, 更有意思的是,Mac中又用了/r. ...

  3. iOS:第三方库使用非ARC编译

    iOS: 解决某些第三方库因为ARC不能使用的问题 1.在target下面的build phases下有一个compile source,下面有很多待编译文件.可以看到一个compile flag,可 ...

  4. datepicker clone 控件错误

    删除id,并删除hasDatepicker //+ -  function changeRows(sender,desc){ var tr = $(sender).closest("tr&q ...

  5. 【WP8】为Webbrowser添加ScrollBar

    在WP8中,控件WebBrowser没有提供对滚动条的支持,而在内置的IE中,却可以显示出滚动条(微软这是在坑我们吗),但如果在客户端使用Webbrowser的话,自己构造ScrollBar来显示 通 ...

  6. 使用 stretchableImageWithLeftCapWidth 方法实现可伸缩图片

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  7. bashrc profile的区别

    bashrc与profile的区别 bashrc和profile的差异在于:1. bashrc是在系统启动后就会自动运行.2. profile是在用户登录后才会运行.3. 进行设置后,可运用sourc ...

  8. create table repo_folder_operate_log_bak as select * from repo_folder_operate_log;

    create table repo_folder_operate_log_bak as select * from repo_folder_operate_log;

  9. Git------创建本地库时绿色标志不显示

    转载: http://blog.csdn.net/zixiao217/article/details/77018392 解决方法: 按Win+R键打开运行对话框,输入 regedit.exe ,准备修 ...

  10. vuejs时间格式化

    date.js export function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, ...