题目链接:hdu4198

题目大意:求起点S到出口的最短花费,其中#为障碍物,无法通过,‘.’的花费为1 ,@的花费为d+1。

需注意起点S可能就是出口,因为没考虑到这个,导致WA很多次.......

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
char map[505][505];
int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int n,m,t;
int begin_x,begin_y,end_x,end_y;
struct node
{
int x,y,time;
friend bool operator < (node a,node b)
{
return a.time > b.time;
}
};
void bfs()
{
priority_queue <node> q;
node s,temp;
s.x = begin_x;
s.y = begin_y;
s.time = 0;
map[begin_x][begin_y] = '#';
q.push(s);
while(!q.empty())
{
temp = q.top();
q.pop();
if(temp.x == end_x && temp.y == end_y)
{
printf("%d\n",temp.time + 1);
return;
}
for(int i = 0 ; i < 4 ; i ++)
{
s.x = temp.x + d[i][0];
s.y = temp.y + d[i][1];
if(s.x < 0 || s.x >= n || s.y < 0 || s.y >= m || map[s.x][s.y] == '#')
continue;
if(map[s.x][s.y] == '.') s.time = temp.time + 1;
else s.time = temp.time + t + 1;
map[s.x][s.y] = '#';
q.push(s);
}
}
}
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&t);
for(i = 0 ; i < n ; i ++)
{
scanf("%s",map[i]);
for(j = 0 ; j < m ; j ++)
{
if(map[i][j] == 'S')
{
begin_x = i;
begin_y = j;
}
if( (i == 0 || i == n - 1 || j == 0 || j == m - 1) && map[i][j] != '#')//刚开始用的else if,没有考虑起点也是终点的情况,WA了很多次
{
end_x = i;
end_y = j;
}
}
}
bfs();
}
return 0;
}

hdu 4198 Quick out of the Harbour(BFS+优先队列)的更多相关文章

  1. HDU - 4198 Quick out of the Harbour (BFS+优先队列)

    Description Captain Clearbeard decided to go to the harbour for a few days so his crew could inspect ...

  2. hdu 4198 Quick out of the Harbour

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4198 Quick out of the Harbour Description Captain Cle ...

  3. hdu 4198:Quick out of the Harbour解题报告

    Quick out of the Harbour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  4. hdu 2102 A计划 具体题解 (BFS+优先队列)

    题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...

  5. hdu 1242 找到朋友最短的时间 (BFS+优先队列)

    找到朋友的最短时间 Sample Input7 8#.#####. //#不能走 a起点 x守卫 r朋友#.a#..r. //r可能不止一个#..#x.....#..#.##...##...#.... ...

  6. hdu 1548 A strange lift 宽搜bfs+优先队列

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548 There is a strange lift.The lift can stop can at ...

  7. hdu 1026 Ignatius and the Princess I(BFS+优先队列)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1026 Ignatius and the Princess I Time Limit: 2000/100 ...

  8. HDU 1312 Red and Black --- 入门搜索 BFS解法

    HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...

  9. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

随机推荐

  1. ASP.NET MVC3中Model验证

    原文:ASP.NET MVC3中Model验证 概述 上节我们学习了Model的数据在界面之间的传递,但是很多时候,我们在数据传递的时候为了确保数据的有效性,不得不给Model的相关属性做基本的数据验 ...

  2. sqlserver备份的几种方式

    1.用sqlserver的维护计划 在这里我就不给截图演示了,这个比较简单,无非就是通过sqlserver自己的维护计划拖拽出2个一个‘备份数据库’任务和一个‘清除维护’任务. 需要注意的点: 1)有 ...

  3. navicat连接oracle一个错误:ORA-12737 Instant Client Light:unsupported server character set ZHS16GBK

    今天使用Navicat连接Oracle数据库.它报告了以下错误:"ORA-12737 Instant Client Light:unsupported server character se ...

  4. Samba(一)通过Samba搭建Linux文件服务器

    本文的目的是为了快速搭建一个linux文件服务器,主要是便于局域网电脑可以方便快速的获得Linux服务器共享的文档(非互传) samba是一个功能十分强大的软件,今天是我们的主角,因为本文是一个演示实 ...

  5. 图文解说PhpStorm 7.0版本语法着色

    前不久,我们测试了PhpStorm7.0版本对PHP 5.5的支持,今天我们将继续对PhpStorm 7.0版本对代码支持进行测试. 我们知道,在PhpStorm 6.0版本中,提供一个黑色背景的代码 ...

  6. ACdream 1195 Sudoku Checker (暴力)

    Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  7. vs2010下载链接中国简体(中国含msdn)

    昨天一个朋友说vs2010中国版可下载,我开始不相信.只是周末.所以,我下载一试 果然,安装了中国版,原本msdn订户才能够下载,感谢朋友们上传. 文件名 cn_visual_studio_2010_ ...

  8. SZU:B47 Big Integer I

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  9. noip推荐系列:汽艇[贪心]

    [问题背景] 一天sxc,zsx,wl到gly坐汽艇,本来和其他的人约好了一起去,结果被放了鸽子,3人便只有一人负担x元去坐汽艇(很贵哦).坐了才发现如果汽艇上人多了位置就不宽敞,就不好玩了.而3个人 ...

  10. go语言 strconv.ParseInt 的例子

    golang strconv.ParseInt 是将字符串转换为数字的函数,功能灰常之强大,看的我口水直流. func ParseInt(s string, base int, bitSize int ...