NYOJ--284--广搜+优先队列--坦克大战
/*
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--广搜+优先队列--坦克大战的更多相关文章
- hdu 1242:Rescue(BFS广搜 + 优先队列)
Rescue Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- 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 ...
- hdoj-1242-Rescue【广搜+优先队列】
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- NYOJ 284 坦克大战 bfs + 优先队列
这类带权的边的图,直接广搜不行,要加上优先队列,这样得到的结果才是最优的,这样每次先找权值最小的,代码如下 #include <stdio.h> #include <iostream ...
- NYOJ 284 坦克大战 【BFS】+【优先队列】
坦克大战 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 Many of us had played the game "Battle city" ...
- nyoj 284 坦克大战 简单搜索
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=284 题意:在一个给定图中,铁墙,河流不可走,砖墙走的话,多花费时间1,问从起点到终点至少 ...
- 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 ...
- HDU 3152 Obstacle Course(优先队列,广搜)
题目 用优先队列优化普通的广搜就可以过了. #include<stdio.h> #include<string.h> #include<algorithm> usi ...
- USACO Milk Routing /// 优先队列广搜
题目大意: 在n个点 m条边的无向图中 需要运送X单位牛奶 每条边有隐患L和容量C 则这条边上花费时间为 L+X/C 求从点1到点n的最小花费 优先队列维护 L+X/C 最小 广搜到点n #inclu ...
随机推荐
- (cljs/run-at (JSVM. :browser) "搭建刚好可用的开发环境!")
前言 书接上一回,在了解cljs基本语法后并在clojurescript.net的奇特错误提示后,我们必须痛定思痛地搭建一个本地的开发环境,以便后续深入地学习cljs. 现有的构建工具 由于浏览器 ...
- jquery fadeIn用法
$("#msgSpan").fadeIn("slow"); setTimeout('$("#msgSpan").hide("slo ...
- 数据的ID名生成新的引用索引树
<?php $arr= [ '0'=>[ "id"=>2, "name"=>"建材", "pid" ...
- php Base64编码文件二进制流主要使用
<?php header( "Content-type: image/jpeg"); //$filename='1.jpg'; //$content=file_get_con ...
- 一起学习c++11——c++11中的新增的容器
c++11新增的容器1:array array最早是在boost中出现:http://www.boost.org/doc/libs/1_61_0/doc/html/array.html 当时的初衷是希 ...
- C#工作笔记
没想到一个Java后端开发还要负责C#桌面程序,我感觉有点方.不过方归方,活还是要干的.简单记录下学到的一些知识点. 1.引用API函数 namespace Demo { class MyUtil { ...
- 搭建ES6运行环境
当ES5还没有完全普及时,ES6就接踵而来了,2015年6月17日,ECMAScript 6发布正式版本,即ECMAScript 2015,我们也简称它为ES6或ES2015.在发布之后的将近一年内, ...
- JavaWeb 后端 <八> 之 JDBC基礎(全)
一.JDBC简介 1.JDBC是SUN公司为了简化操作数据推出一套规范.数据库厂商的驱动就是对JDBC的实现. 2.Java Data Base Connectivity(java数据库连接),它主要 ...
- js获取鼠标点击的对象,点击另一个按钮删除该对象
作为js的一名新手,对于所谓的event的了解并不是太多,仅仅根据视频教学中的例子模仿着,写了诸如: function funcname(e) { e=window.event||event };的函 ...
- socket 异步通信的一些问题
socket通信在使用时被封装很简单,像操作文件一样简单,正是因为简单里面好多细节需要深入研究一下. windows下通信有select和iocp方式,select是传统方式,在socket里使用re ...