zoukankan      html  css  js  c++  java
  • hdoj1010

    Tempter of the Bone

    奶奶的,这道题用了我一下午的时间,只是调用dfs时用错了一个参数,怎么也没想到会是这样出错。错误的代码竟然能过测试数据和我自己的数据,无语啊。

    /***************************************************************\
    *Author: 小呼
    *Created Time: Sun 11 Jul 2010 05:33:54 PM CST
    *File Name: a.cpp
    *Description:回溯
    \***************************************************************/

    //*========================*Head File*========================*\\

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    /*----------------------*Global Variable*----------------------*/
    int
    N,M,T,di,dj;
    char
    maze[
    9][9];
    bool
    escape;
    int
    dir[
    4][2]={{0,-1},{0,1},{1,0},{-1,0}};
    //*=======================*Main Program*=======================*//
    using namespace std;
    void
    dfs(int sr,int sc,int t){
    if
    (sr<=
    0||sr>N||sc<=0||sc>M)return;

    if
    (escape||(sr==di&&sc==dj&&t==
    0)){
    escape=
    1;
    return
    ;
    }

    int
    tem=t-abs(sr-di)-abs(sc-dj);
    if
    (tem<
    0||tem&1)
    return
    ;
    maze[sr][sc]=
    'X';
    for
    (int i=
    0;i<4;++i){
    if
    (maze[sr+dir[i][
    0]][sc+dir[i][1]]!='X'){
    dfs(sr+dir[i][
    0],sc+dir[i][1],t-1);
    if
    (escape)return;
    }
    }

    maze[sr][sc]=
    '.';
    }


    int
    main(){
    int
    sr,sc;
    while
    (cin>>N>>M>>T){
    if
    (N==
    0&&M==0&&T==0)
    break
    ;
    int
    wall=
    0;
    for
    (int i=
    1;i<=N;++i)
    for
    (int j=
    1;j<=M;++j){
    cin>>maze[i][j];
    if
    (maze[i][j]==
    'X')
    wall++;
    else if
    (maze[i][j]==
    'S'){
    sr=i;sc=j;
    }

    else if
    (maze[i][j]==
    'D'){
    di=i;dj=j;
    }
    }

    if
    (N*M-wall<=T){
    cout<<
    "NO\n";
    continue
    ;
    }

    escape=
    0;
    dfs(sr,sc,T);
    if
    (escape)
    cout<<
    "YES\n";
    else

    cout<<
    "NO\n";
    }
    }



  • 相关阅读:
    memwatch使用简化
    memwatch检测内存泄露
    mtrace检测内存泄露
    2.14 环境变量及参数
    设计模式[索引]
    二叉树遍历
    AppCan 双击返回按钮退出应用
    MySQL语句相关经验总结
    mysql连接失败或出现“Too many connections”错误
    让IE的Button自适应文字宽度兼容
  • 原文地址:https://www.cnblogs.com/Open_Source/p/1904934.html
Copyright © 2011-2022 走看看