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. Testcase篇

    1: forever @(); 等待,c触发event. forever @(`SOC_TESTBENCH_NAME.vt_event1);在整个case的执行过程中,只要.c触发event1,就执行 ...

  2. 《zw版·Halcon-delphi系列原创教程》 水果自动分类脚本(机器学习、人工智能)

    <zw版·Halcon-delphi系列原创教程> 水果自动分类脚本(机器学习.人工智能) 前面介绍了超市,流水线,酸奶的自动分类算法,下面再介绍一个水果的自动分类算法. Halcon强大 ...

  3. zw版【转发·台湾nvp系列Delphi例程】Delphi 使用 HALCON库件COM控件数据格式转换

    zw版[转发·台湾nvp系列Delphi例程]Delphi 使用 HALCON库件COM控件数据格式转换 Delphi 使用 HALCON库件COM控件数据格式转换,与IHObjectX接口有关 va ...

  4. TP主从服务器配置

    在config.php文件中,设置‘DB_DEPLOY_TYPE’=>1,‘DB_HOST’=>‘localhost,192.168.0.1,192.168.0.23’,各个主机之间用逗号 ...

  5. UIPage

    分页控件是一种用来取代导航栏的可见指示器,方便手势直接翻页,最典型的应用便是iPhone的主屏幕,当图标过多会自动增加页面,在屏幕底部你会看到原点,用来只是当前页面,并且会随着翻页自动更新. 一.创建 ...

  6. ch2-3:模块的使用-window环境

    导入模块:import 模块名 完成如下工作: 1.编写一个小程序testmodule.py,导入新建的模块nester,并定义一个小列表cast,然后使用调用模块中的函数打印列表到屏幕上: impo ...

  7. 调整iFrame高度

    在Chrome中,即使将iframe的高度设置为100%,也无法根据内容页自动调节高度,需要在iframe的onload even中通过计算设置iframe的高度 function setIframe ...

  8. c#之线程池优先级

    using System; using System.Threading; namespace ConsoleApplication1 { class Program { static void Ma ...

  9. NotificationObject.cs

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  10. 跨站点脚本编制实例(AppScan扫描结果)

    最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中有很多是关于跨站点脚本编制问题的.下面就把这块东西分享出来. 原创文章,转载请注明 ------------------ ...