http://acm.hdu.edu.cn/showproblem.php?pid=4308

Saving Princess claire_

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2305    Accepted Submission(s): 822

Problem Description
Princess claire_ was jailed in a maze by Grand Demon Monster(GDM) teoy.
Out of anger, little Prince ykwd decides to break into the maze to rescue his lovely Princess.
The
maze can be described as a matrix of r rows and c columns, with grids,
such as 'Y', 'C', '*', '#' and 'P', in it. Every grid is connected with
its up, down, left and right grids.
There is only one 'Y' which means the initial position when Prince ykwd breaks into the maze.
There is only one 'C' which means the position where Princess claire_ is jailed.
There
may be many '*'s in the maze, representing the corresponding grid can
be passed through with a cost of certain amount of money, as GDM teoy
has set a toll station.
The grid represented by '#' means that you can not pass it.
It is said that as GDM teoy likes to pee and shit everywhere, this grid is unfortunately damaged by his ugly behavior.
'P'
means it is a transmission port and there may be some in the maze.
These ports( if exist) are connected with each other and Prince ykwd can
jump from one of them to another.

They say that there used to
be some toll stations, but they exploded(surely they didn't exist any
more) because of GDM teoy's savage act(pee and shit!), thus some
wormholes turned into existence and you know the following things.
Remember, Prince ykwd has his mysterious power that he can choose his
way among the wormholes, even he can choose to ignore the wormholes.
Although
Prince ykwd deeply loves Princess claire_, he is so mean that he
doesn't want to spend too much of his money in the maze. Then he turns
up to you, the Great Worker who loves moving bricks, for help and he
hopes you can calculate the minimum money he needs to take his princess
back.

 
Input
Multiple cases.(No more than fifty.)
The
1st line contains 3 integers, r, c and cost. 'r', 'c' and 'cost' is as
described above.(0 < r * c <= 5000 and money is in the range of
(0, 10000] )
Then an r * c character matrix with 'P' no more than 10%
of the number of all grids and we promise there will be no toll
stations where the prince and princess exist.
 
Output
One
line with an integer, representing the minimum cost. If Prince ykwd
cannot rescue his princess whatever he does, then output "Damn
teoy!".(See the sample for details.)
 
Sample Input
1 3 3
Y*C
1 3 2
Y#C
1 5 2
YP#PC
 
Sample Output
3
Damn teoy!
0
 题目唯一需要注意的是,P是传送带,可进入所有传送带。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n,m,V;
char map[][];
int v[][];
struct node
{
int x,y,ans;
}q[];
int jx[]={,-,,};
int jy[]={,,,-};
void bfs(int xx,int yy)
{
int e=;
int s=;
memset(v,,sizeof(v));
struct node t,f;
t.x=xx;
t.y=yy;
t.ans=;
v[t.x][t.y]=;
q[e++]=t;
while(s<e)
{
t=q[s++];
if(map[t.x][t.y]=='C')
{
printf("%d\n",t.ans);
return ;
}
for(int i=;i<;i++)
{
f.x=t.x+jx[i];
f.y=t.y+jy[i];
if(f.x>=&&f.x<n&&f.y>=&&f.y<m&&map[f.x][f.y]!='#'&&v[f.x][f.y]==)
{
if(map[f.x][f.y]=='*')
{
f.ans=t.ans+V;
q[e++]=f;
v[f.x][f.y]=;
}
else if(map[f.x][f.y]=='C')
{
f.ans=t.ans;
q[e++]=f;
v[f.x][f.y]=;
}
else if(map[f.x][f.y]=='P')
{
for(int j=;j<n;j++)
{
for(int k=;k<m;k++)
{
if(map[j][k]=='P')
{
f.ans=t.ans;
f.x=j;
f.y=k;
q[e++]=f;
v[f.x][f.y]=;
}
}
}
}
}
}
}
printf("Damn teoy!\n");
return ;
}
int main()
{
int xx,yy;
while(scanf("%d%d%d",&n,&m,&V)!=EOF)
{
for(int i=;i<n;i++)
scanf("%*c%s",map[i]);
int j;
for(int i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(map[i][j]=='Y')
{
xx=i;
yy=j;
break;
}
}
if(j!=m) break;
}
bfs(xx,yy);
}
return ;
}
 

Saving Princess claire_(hdu 4308 bfs模板题)的更多相关文章

  1. HDU 4308 Saving Princess claire_(简单BFS)

    求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...

  2. HDU 4308 BFS Saving Princess claire_

    原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...

  3. hdu 4308 Saving Princess claire_

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...

  4. 2012 #1 Saving Princess claire_

    Saving Princess claire_ Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  5. hdu----(4308)Saving Princess claire_(搜索)

    Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. POJ-2251 Dungeon Master (BFS模板题)

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  7. hdu1242 又又又是逃离迷宫(bfs模板题)

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1242/ 这次的迷宫是有守卫的,杀死一个守卫需要花费1个单位的时间,所以以走的步数为深度,在每一层进行搜索,由于走 ...

  8. POJ:Dungeon Master(三维bfs模板题)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 D ...

  9. HDU 2138 Miller-Rabin 模板题

    求素数个数. /** @Date : 2017-09-18 23:05:15 * @FileName: HDU 2138 miller-rabin 模板.cpp * @Platform: Window ...

随机推荐

  1. 【thinkphp5】使用tp5开发api接口 定义全局异常处理

    1 新建文件夹以及文件 路径: /application/lib/exception/ExceptionHandler.php 并键入以下代码 <?php namespace app\lib\e ...

  2. 【python3】urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

    在玩爬虫的时候,针对https ,需要单独处理.不然就会报错: 解决办法:引入 ssl 模块即可 核心代码 imort ssl ssl._create_default_https_context = ...

  3. Oracle 12C 创建用户连接pdb

    测试环境: C:\ora12c\product\12.1.0\dbhome_1\BIN>sqlplus.exe /nolog SQL*Plus: Release 12.1.0.1.0 Produ ...

  4. sencha touch 扩展官方NavigationView 灵活添加按钮组,导航栏,自由隐藏返回按钮(2014-5-15)

    扩展视频讲解:http://www.cnblogs.com/mlzs/p/3652094.html官方NavigationView详解:http://www.cnblogs.com/mlzs/p/35 ...

  5. Installed .NET Framework 4.5 Ajax POST IIS hang

    去年我已写过一篇关于安装.NET Framework 4.5后特定场景Ajax POST的挂起问题 => http://www.cnblogs.com/junchu25/archive/2012 ...

  6. ubuntu下文件压缩/解压缩

    ubuntu下文件压缩/解压缩 http://blog.csdn.net/luo86106/article/details/6946255 .gz 解压1:gunzip FileName.gz 解压2 ...

  7. 在线工具-程序员的工具箱-在线Cron表达式生成器

    在线Cron表达式生成器 http://cron.qqe2.com/ 在线工具 - 程序员的工具箱 https://tool.lu/

  8. eclipse配置Js环境spket

    网上下载spket-1.6.16.jar破解版(目前最新版本) 1.如果你的JDK在1.6以上,可以直接双击spket-1.6.16.jar运行安装. 其它,使用命令行方式.(注意:自己切换命令行到s ...

  9. Scikit-Learn实战KNN

    Scikit-Learn总结 Scikit-Learn(基于Python的工具包) 1.是一个基于Numpy,Scipy,Matplotlib的开源机器学习工具包. 2.该包于2007年发起,基本功能 ...

  10. PAT-GPLT L1-033 - 出生年 - [简单模拟]

    题目链接:https://www.patest.cn/contests/gplt/L1-033 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standar ...