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. 【sql进阶】查询每天、每个设备的第一条数据

    需求如下 每个设备(不同DeviceID).每天会向数据库插入多条数据,求每天.每个设备插入的第一条数据. 下面SQL中的 ShareRecommendID 类比不同设备的DeviceID. ROW_ ...

  2. PHP魔术变量和魔术方法

    基础知识:魔术变量和魔术方法 魔术变量:最初PHP魔术变量的出现主要是为了方便开发者调试PHP的代码;当然也可以利用这个实现特殊需求.在写法上魔术变量前后都有两个下划线. 如:_LINE_:返回文件中 ...

  3. 云计算设计模式(二十一)——Sharding分片模式

    云计算设计模式(二十一)——Sharding分片模式 将一个数据存储到一组水平分区或碎片.存储和访问大量数据时,这个模式可以提高可扩展性. 背景和问题 由一个单一的服务器托管的数据存储区可能会受到以下 ...

  4. CacheDependency 的使用方法

    //创建缓存依赖项 CacheDependency dep = new CacheDependency(fileName); //创建缓存 HttpContext.Current.Cache.Inse ...

  5. Redis学习笔记--Redis配置文件redis.conf参数配置详解

    ########################################## 常规 ########################################## daemonize n ...

  6. sencha touch NavigationView 嵌套 TabPanel 的问题

    在st2.1之中,在NavigationView视图之中在嵌套一个TabPanel会有以下问题 下面我们监控TabPanel的activate事件和activeitemchange事件 会发现当首页加 ...

  7. nginx 启动重启脚本

    #! /bin/sh # Default-Start:     2 3 4 5 # Default-Stop:      0 1 6 # Short-Description: starts the n ...

  8. SSH使用秘钥和别名登陆服务器

    手工配置免密码及别名登陆 第一步:生成秘钥 $ ssh-keygen -t rsa 第二步:上传公钥到目标服务器 $ ssh-copy-id -i ~/.ssh/id_rsa.pub <romt ...

  9. [通信] C#多线程Socket-文件传输

    FileSendClient : Form1.cs using System; using System.IO; using System.Net; using System.Net.Sockets; ...

  10. 如何搭建SoC项目的基本Testbench【zz】

    原文地址:http://bbs.eetop.cn/thread-442797-1-8.html 写这个文档的目的是让大家对搭建SoC项目的Testbench有一个比较清晰的认识,可以根据这个文档来一步 ...