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. 夺命雷公狗---TP商城----TP之样式和特效以及图片引入---2

    ---恢复内容开始--- 刚才见到笑脸了,那么下一步就到我们的shop目录下创建一个Admin的目录了,然后将Home目录里面的东西全部都拉进去即可 然后我们回到shop\Home\View目录下创建 ...

  2. delphi 读取excel 两种方法

    http://www.cnblogs.com/ywangzi/archive/2012/09/27/2705894.html 两种方法,一是用ADO连接,问题是Excel文件内容要规则,二是用OLE打 ...

  3. dbms_sql包的用法

    http://blog.itpub.net/20948385/viewspace-691398 对于一般的select操作,如果使用动态的sql语句则需要进行以下几个步骤: open   cursor ...

  4. batch批的概念

    批处理(Batch Requests), 批处理简单理解为同时执行的一批SQL处理语句,一个批处理中可能有多个DML.多个存储过程等等.如在SSMS操作,每个'GO'执行前都属于一个批处理. 注意区分 ...

  5. ASP.NET MVC4中的bundles特性引发服务器拒绝访问(403错误)

    在ASP.NET MVC4中微软引入了bundles特性,这个特性可以将服务器端的多个Javascript或多个css文件捆绑在一起作为一个单一的URL地址供客户端浏览器调用,从而减少了页面上Http ...

  6. QTP常用功能

    1.QTP录制过程的截图 查看录制脚本过程中QTP的截图可以在QTP中查找,在关键字视图中点击每一步都对应一个截图   2.在关键字视图中为测试步骤添加注释 在关键字视图中表格列头中单击鼠标右键,选择 ...

  7. android实操--练习1

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

  8. Java汉诺塔算法

    汉诺塔问题[又称河内塔]是印度的一个古老的传说. 据传开天辟地之神勃拉玛在一个庙里留下了三根金刚石的棒,第一根上面套着64个圆的金片,最大的一个在底下,其余一个比一个小,依次叠上去,庙里的众僧不倦地把 ...

  9. 常用的rpm和yum的一些命令

    常用的rpm命令  rpm -qa | grep coreutils    <-- 查看系统上是否已经安装了coreutils  rpm -qi coreutils           < ...

  10. Java的深度克隆和浅度克隆

    说到克隆,其实是个比较简单的概念,跟现实生活正的克隆一样,复制一个一模一样的对象出来.clone()这个方法是从Object继承下来的,一个对象要实现克隆,需要实现一个叫做Cloneable的接口,这 ...