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. [php] PHPExcel插入图片

    其它的代码就不贴了,直接上关键代码: $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objActSh ...

  2. [OrangePi] Installation on SD Card

    Download any of the available images (xz archive) from Mega or GoogleDrive Download scriptbin_kernel ...

  3. zw版【转发·台湾nvp系列Delphi例程】HALCON FillUpShape1

    zw版[转发·台湾nvp系列Delphi例程]HALCON FillUpShape1 procedure TForm1.Button1Click(Sender: TObject);var img : ...

  4. Auto push git tag

    CALL "C:\Program Files\TortoiseGit\bin\pageant.exe" "d:\CKey.ppk" set GIT_SSH=C: ...

  5. Swift常量和变量

    常量和变量由一个特定名称来表示,如maxNumber 或者 message.常量所指向的是一个特定类型的值, 如数字10或者字符”hello”.变量的值可以根据需要不断修改,而常量的值是不能够被二次修 ...

  6. [置顶] 1D1D动规优化初步

    例题一: 货物运输,大意: 给出N个点的坐标与需要你送过去的钱数(第一个点不需要钱),身上带钱的数目有最大值,由初始在的1点,按顺序经历每个点(中途可以回1点,回去钱就满了),问最小走的路程是多少(最 ...

  7. android 应用架构随笔四(View、ViewGroup)

    View表示了用户界面的基本构建模块. 一个View占用了屏幕上的一个矩形区域并且负责界面绘制和事件处理.手机屏幕上所有看得见摸得着的都是View. Activity是四大组件中唯一一个用来和用户进行 ...

  8. android 学习随笔七(网络:图片及文本传输及线程关系 )

    主线程.子线程.UI的关系 简单的HTTP请求 -------------------------------------------------------- public class MainAc ...

  9. JS实现复制网页内容自动加入版权内容代码和原文链接

    JS实现复制网页内容自动加入版权内容代码和原文链接 实现代码:在body内放入如下代码即可: <script type="text/javascript"> var S ...

  10. iOS 警告窗口

    - (IBAction)buttonPressed:(id)sender {        NSDate *date=self.datePicker.date;    NSString *messag ...