/*
    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. 跨域访问之JSONP

    跨域 在平常的工作中常常会遇到A站点的需要访问B站点的资源. 这时就产生了跨域访问. 跨域是指从一个域名的网页去请求另一个域名的资源.浏览器遵循同源策略,不允许A站点的Javascript 读取B站点 ...

  2. php提示php_network_getaddresses: getaddrinfo failed: Name or service not known

    php_network_getaddresses: getaddrinfo failed: Name or service not known 面对这个错误,已经相对熟悉了.想起来应该是服务器无法访问 ...

  3. php解决表单重复提交

    php解决表单重复提交时间:2015-2-28 | 评论:1条评论 | 被查看了 189 次 | 标签:php, W3cui重复提交是我们开发中会常碰到的一个问题,除了我们使用js来防止表单的重复提交 ...

  4. cisco模拟器之------交换机、路由器、vlan的综合实例

    主要实现功能:a)位于路由器同一侧的不同网段的主机之间实现通信. b)  位于不同路由器的主机之间实现通信. 网络拓扑图: 命令配置: switch0的配置: Switch(config)#vlan ...

  5. 类间调用inline函数的效率

    问题描述: class A { public: int x, y, k, NY; inline int f(int i, int j, int k)  {return ((i)*(NY + 1) * ...

  6. 推荐一个基于Vue2.0的的一款移动端开发的UI框架,特别好用。。。

    一丶YDUI 一只注重审美,且性能高效的移动端&微信UI. 下面为地址自己研究去吧! 我的项目正在用,以前用的Mint-ui但是现在感觉还是这个好一点,官方给出的解释很清楚,很实用. 官方地址 ...

  7. css 背景图片自适应

    body{ height:100%; overflow:hidden;} .bg { background-image: url(../../img/beijing.jpg); width:100%; ...

  8. 基于GCC的openMP学习与测试(2)

    一.openMP简单测试 1.简单测试(1) #include<omp.h> #include<time.h> #include<iostream> using n ...

  9. mac重开电脑后显示重装提示解决办法

    情况描述: mac昨天电脑关闭后 第二天打开电脑就显示语言选择安装语言 解决办法: 1  出现语言安装提示界面  我们选择简体中文 2  出现苹果密码登陆    我们选择下面的按钮点击退出  这样就可 ...

  10. [IB配置]PeopleSoft如何重置网关属性administrator密码

    当您在登陆主菜单>PeopleTools>继承代理程序>配置>网关>网关设置属性在尝试打开网关属性配置时候,需要输入账号:administrator以及密码,有时候在升级 ...