Saving Princess claire_

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 #include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
const int inf=0x3f3f3f3f; struct Node
{
int x;
int y;
};
char mp[][];
int d[][],sx,sy,gx,gy,nump;
int dx[]={,,-,},dy[]={,,,-};
Node P[]; int main()
{
int n,m,c;
int i,j;
while(scanf("%d %d %d",&n,&m,&c)!=EOF)
{
nump=;
getchar();
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
d[i][j]=inf;
scanf("%c",&mp[i][j]);
if(mp[i][j]=='Y')
sx=i,sy=j;
if(mp[i][j]=='C')
gx=i,gy=j;
if(mp[i][j]=='P')
{
nump++;
P[nump].x=i,P[nump].y=j;
}
}
getchar();
} queue<Node> que;
while(que.size()) que.pop();
Node s;
s.x=sx,s.y=sy;
que.push(s);d[sx][sy]=; while(que.size())
{
Node now=que.front(),nex;
/*for(i=1;i<=m;i++)
printf("%d ",d[1][i]);
printf("\n");
printf("%d\n",now.y);*/
que.pop(); for(i=;i<;i++)
{
int nx=now.x+dx[i],ny=now.y+dy[i];
if(<=nx && nx<=n && <=ny && ny<=m && mp[nx][ny]!='#')
{
int value=d[now.x][now.y];
if(mp[nx][ny]=='*')
value++;
if(mp[nx][ny]=='P')
{
for(j=;j<=nump;j++)
{
if(value<d[P[j].x][P[j].y])
{
que.push(P[j]);
d[P[j].x][P[j].y]=value;
}
}
}
else
{
if(value<d[nx][ny])
{
//printf("%d %d %d\n",now.x,ny,value);
nex.x=nx,nex.y=ny;
que.push(nex);
d[nx][ny]=value;
}
}
}
}
} if(d[gx][gy]==inf)
printf("Damn teoy!\n");
else
printf("%d\n",d[gx][gy]*c);
}
return ;
}
/*
1 7 5
PY**C*P
*/

2012 #1 Saving Princess claire_的更多相关文章

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

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

  2. hdu 4308 Saving Princess claire_

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

  3. HDU 4308 BFS Saving Princess claire_

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

  4. Saving Princess claire_(hdu 4308 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...

  5. hdu 4308 Saving Princess claire_ BFS

    为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...

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

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

  7. BFS(最短路) HDOJ 4308 Saving Princess claire_

    题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...

  8. ZOJ 3369 Saving Princess

    Saving Princess Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...

  9. UESTC 1811 Hero Saving Princess

    九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/11104265 题目链接 :http://222.197.181.5/proble ...

随机推荐

  1. 夺命雷公狗ThinkPHP项目之----企业网站17之网站配置页的添加

    为了网站可以智能一点,所以我们开始来写一个网站配置的功能.. 所以我来写他的数据表: 先来完成他的添加功能,页面效果如下所示: lists.html代码如下所示: <!doctype html& ...

  2. zw版_zw中文增强版Halcon官方Delphi例程

    [<zw版·delphi与halcon系列原创教程>zw版_zw中文增强版Halcon官方Delphi例程 源码下载:http://files.cnblogs.com/files/ziwa ...

  3. Windows应用层网络模块扫盲

           说到Windows应用层网络通信不得不提winsock,winsock是工作在TCP/IP层的应用层(TCP/IP层分为主机到网络层[比特].网络互联层[数据帧].传输层[数据包].应用 ...

  4. 帮初学者改代码——playerc之“练习:求完数问题”(下)

    前文链接:帮初学者改代码——playerc之“练习:求完数问题”(上) 再来看看be_ferfect()应该如何改. be_ferfect()函数的功能是判断number是否为完数,同时把因子对写入d ...

  5. android实操--练习1

    这两天有空,打算把一些文档整理一下,快要考试了,找一些简单的例子来做做,重温安卓的知识. 下面是第一个练习: 实现很简单,下面我们来看看: 首先新建一个安卓项目Demo1 接着是界面的布局(包括act ...

  6. Intel Edison

    起步: https://software.intel.com/zh-cn/node/628224 刷机: https://software.intel.com/zh-cn/flashing-firmw ...

  7. linux 使用串口连接设备console

    linux使用串口连接cisco设备的console   linux 自带一个串口命令:minicom,需要经过设置,之后就可以连接了.   传说是默认就可以,我可能RP不好,我必须要经过设置才可以. ...

  8. printf,sprintf,vsprintf 区别【转】

    转自:http://blog.csdn.net/anye3000/article/details/6593551 有C语言写作历史的程序员往往特别喜欢printf 函数.即使可以使用更简单的命令(例如 ...

  9. JavaScript DOM 编程艺术(第2版)读书笔记(4)

    案例研究:JavaScript 图片库 改变图片的src属性的两种方式: 1,setAttribute方法是“第1级DOM”的组成部分,它可以设置元素节点的任意属性. 2,element.src = ...

  10. DBUtils开源JDBC类库,对JDBC简单封装(作用是:简化编码工作量,同时不会影响程序的性能)

    DBUtils:提高了程序的性能,编程更加简便 架包 mysql-connector-java-jar commons-dbcp-1.4jar commons-pool-1.5.5jar common ...