/*
    Name: NYOJ--284--坦克大战
    Author: shen_渊
    Date: 14/04/17 19:08
    Description: 广度优先搜索+优先队列
                注意清空地图
                对输入地图进行了预处理,将S,R设置为#
*/

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const char YOU = 'Y';
const char TARGET = 'T';
const char RIVER = 'R' ;
const char SWALL = 'S';
const char BWALL = 'B';
const char EMPOTY = 'E';
const char FORBID = '#';
struct node{
    int x,y,steps;
    node():steps(){};
    bool operator <(const node &a)const{
        return steps>a.steps;
    }
}you,target;
int bfs();
int check(char);
][] = {};
int m,n;
][] = {{,},{,-},{,},{-,}};
int main()
{
//    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);

    while(cin>>m>>n, m || n) {
        int i,j;
        memset(map,,sizeof(map));
        ; i<=m; ++i){
            ; j<=n; ++j){
                cin>>map[i][j];
                switch(map[i][j]){
                    case YOU:{
                        you.x = i;you.y = j;
                        break;
                    }
                    case TARGET:{
                        target.x = i;target.y = j;
                        break;
                    }
                    case RIVER:
                    case SWALL:{
                        map[i][j] =='#';
                        break;
                    }
                    default:break;
                }
            }
        }
        cout<<bfs()<<endl;
    }
    ;
}
int bfs(){
    priority_queue<node> Q;
    while(!Q.empty())Q.pop();
    Q.push(you);
    map[you.x][you.y] = '#';
    while(!Q.empty()){
        node p = Q.top();Q.pop();
        int i,j;
        ; i<; ++i){
            node a;
            a.x = p.x + dir[i][];
            a.y = p.y + dir[i][];
            || a.y<|| a.x>m|| a.y>n)continue;
            int next;
            if(next = check(map[a.x][a.y])){
                a.steps = p.steps + next;
                if(a.x == target.x && a.y == target.y)return a.steps;
                Q.push(a);
                map[a.x][a.y] = '#';
            }
        }
    }
    ;
}
int check(char ch){
    switch(ch){
        ;
        ;
        ;
    }
    ;
}

NYOJ--284--广搜+优先队列--坦克大战的更多相关文章

  1. hdu 1242:Rescue(BFS广搜 + 优先队列)

    Rescue Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  2. HDU - 3345 War Chess 广搜+优先队列

    War chess is hh's favorite game: In this game, there is an N * M battle map, and every player has hi ...

  3. hdoj-1242-Rescue【广搜+优先队列】

    Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  4. NYOJ 284 坦克大战 bfs + 优先队列

    这类带权的边的图,直接广搜不行,要加上优先队列,这样得到的结果才是最优的,这样每次先找权值最小的,代码如下 #include <stdio.h> #include <iostream ...

  5. NYOJ 284 坦克大战 【BFS】+【优先队列】

    坦克大战 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 Many of us had played the game "Battle city" ...

  6. nyoj 284 坦克大战 简单搜索

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284 题意:在一个给定图中,铁墙,河流不可走,砖墙走的话,多花费时间1,问从起点到终点至少 ...

  7. hdu 1026:Ignatius and the Princess I(优先队列 + bfs广搜。ps:广搜AC,深搜超时,求助攻!)

    Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  8. HDU 3152 Obstacle Course(优先队列,广搜)

    题目 用优先队列优化普通的广搜就可以过了. #include<stdio.h> #include<string.h> #include<algorithm> usi ...

  9. USACO Milk Routing /// 优先队列广搜

    题目大意: 在n个点 m条边的无向图中 需要运送X单位牛奶 每条边有隐患L和容量C 则这条边上花费时间为 L+X/C 求从点1到点n的最小花费 优先队列维护 L+X/C 最小 广搜到点n #inclu ...

随机推荐

  1. 如何为一个eclipse安装android环境

    据说android已经不再支持android adt-bundle的开发环境了,所以如果继续使用的话,会不再更新 使用eclipse来安装android环境或者使用android studio 但是以 ...

  2. 富文本编辑器嵌入指定html代码

    先把内容放入一个input中 <input id="detail" type="hidden" value="${sysCarousel.det ...

  3. ExtJs异步无法向外传值和赋值的解决办法,亲测有效

    1.Ext.data.Store.load();方法是异步的,下面的方式获得的reCount始终是0,因为还没等后台的方法执行完就赋值了,此时store的record还没获得值. var testSt ...

  4. gulp 运用 的理解

    ugulp.task('build', function() { runSequence('clean', 'copy', ['uglify', 'sass', 'htmlmin'], 'base64 ...

  5. 基于angular4.0分页组件

    分页组件一般只某个页面的一小部分,所以我们它是子组件 当然如果你承认这话的,可以往下看,因为我把他当作子组建来写了 分页组件的模版 import { Component } from '@angula ...

  6. 总结两种动态代理jdk代理和cglib代理

    动态代理 上篇文章讲了什么是代理模式,为什么用代理模式,从静态代理过渡到动态代理. 这里再简单总结一下 什么是代理模式,给某个对象提供一个代理对象,并由代理对象控制对于原对象的访问,即客户不直接操控原 ...

  7. 防止js全局变量污染方法总结

    javaScript 可以随意定义保存所有应用资源的全局变量.但全局变量可以削弱程序灵活性,增大了模块之间的耦合性.在多人协作时,如果定义过多的全局变量 有可能造成全局变量冲突,也就是全局变量污染问题 ...

  8. linux实训

    目  录 Unit 1 操作系统安装.... 3 1.1 多操作系统安装... 3 1.1.1 VMware简介... 3 1.1.2 VMWare基本使用... 4 1.2 安装Red Hat Li ...

  9. C++学习(二) 入门篇

      程序清单2. carrots.cpp //carrots.cpp - - food processing program //uses and displays a variable #inclu ...

  10. MongoDB数据库索引构建情况分析

    前面的话 本文将详细介绍MongoDB数据库索引构建情况分析 概述 创建索引可以加快索引相关的查询,但是会增加磁盘空间的消耗,降低写入性能.这时,就需要评判当前索引的构建情况是否合理.有4种方法可以使 ...