/*
    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. PHP中小小的header函数

    不废话,直接说功能 1.重定向,语法: header("location:http://www.lemon-x.ga"); file_put_contents("./te ...

  2. 后端对数组json_encode,前端遍历输出

    echo json_encode($get_city_lists); <script type="text/javascript"> function get_city ...

  3. [leetcode-508-Most Frequent Subtree Sum]

    Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a ...

  4. 如何利用keytool查看一个apk的签名

  5. centos生成公钥私钥 securecrt通过公钥访问服务器 winscp通过公钥访问服务器

    忙碌了一下午,一直到写博客现在.都在纠结阿里云服务器上配置公钥私钥,网上的说辞总是参差不齐,需要各个去综合,合理取舍.今天终于配置好了. 我就不说这种方式的重要性了,往往黑客都不需要你的登陆账户密码就 ...

  6. 统计学习方法 三 kNN

    KNN (一)KNN概念: K近邻算法是一种回归和分类算法,这主要讨论其分类概念: K近邻模型三要素: 1,距离: 2,K值的选择: K值选择过小:模型过复杂,近似误差减小,估计误差上升,出现过拟合 ...

  7. Ionic 常用组件解析

    Ionic 常用组件解析 $ionicModal(弹出窗口): //创建一个窗口 //此处注意目录的起始位置为app $ionicModal.fromTemplateUrl('app/security ...

  8. net 中web.config单一解决方法 (其他配置引入方式)

    近期一个项目需要写许多的配置项,发现在单个web.config里面写的话会很乱也难于查找 所以搜了一下解决了,记录下来 一.   webconfig提供了引入其他config的方式 <conne ...

  9. haproxy+tomcat集群搭建

    web1和web2的部署可参考我之前的文章<Tomcat集群搭建>,这里就省去该过程了. #安装haproxy- .tar.gz cd haproxy-/ make TARGET=linu ...

  10. 第2篇:用as3.0制作一个滚动条组件

    本实例演示了实现一个滚动条基本功能的制作方法,没有添加改变皮肤,修改滚动条视框大小等功能,有兴趣的朋友可根据自己要求自行添加.使用时只需要通过以下一行代码创建滚动条组件: var myScrollba ...