博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2012 #1 Saving Princess claire_
阅读量:6272 次
发布时间:2019-06-22

本文共 4532 字,大约阅读时间需要 15 分钟。

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

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
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 const int inf=0x3f3f3f3f; 7 8 struct Node 9 { 10 int x; 11 int y; 12 }; 13 char mp[5005][5005]; 14 int d[5005][5005],sx,sy,gx,gy,nump; 15 int dx[4]={
1,0,-1,0},dy[4]={
0,1,0,-1}; 16 Node P[505]; 17 18 int main() 19 { 20 int n,m,c; 21 int i,j; 22 while(scanf("%d %d %d",&n,&m,&c)!=EOF) 23 { 24 nump=0; 25 getchar(); 26 for(i=1;i<=n;i++) 27 { 28 for(j=1;j<=m;j++) 29 { 30 d[i][j]=inf; 31 scanf("%c",&mp[i][j]); 32 if(mp[i][j]=='Y') 33 sx=i,sy=j; 34 if(mp[i][j]=='C') 35 gx=i,gy=j; 36 if(mp[i][j]=='P') 37 { 38 nump++; 39 P[nump].x=i,P[nump].y=j; 40 } 41 } 42 getchar(); 43 } 44 45 queue
que; 46 while(que.size()) que.pop(); 47 Node s; 48 s.x=sx,s.y=sy; 49 que.push(s);d[sx][sy]=0; 50 51 while(que.size()) 52 { 53 Node now=que.front(),nex; 54 /*for(i=1;i<=m;i++) 55 printf("%d ",d[1][i]); 56 printf("\n"); 57 printf("%d\n",now.y);*/ 58 que.pop(); 59 60 for(i=0;i<4;i++) 61 { 62 int nx=now.x+dx[i],ny=now.y+dy[i]; 63 if(1<=nx && nx<=n && 1<=ny && ny<=m && mp[nx][ny]!='#') 64 { 65 int value=d[now.x][now.y]; 66 if(mp[nx][ny]=='*') 67 value++; 68 if(mp[nx][ny]=='P') 69 { 70 for(j=1;j<=nump;j++) 71 { 72 if(value
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4771438.html

你可能感兴趣的文章
5G标准化进程提速 射频器件市场空间将打开
查看>>
《分布式系统:概念与设计》一3.3.6 拥塞控制
查看>>
“烧烤模式”下 安防设备如何经得住考验?
查看>>
人工智能时代,语音技术怎么赚钱?
查看>>
美大选被攻击 未来选举要回归纸质选票?
查看>>
SCRM火了,SaaS服务再现新风口
查看>>
黑客站在ATM机面前就直接吐出钞票 如何做到的?
查看>>
TensorFlow教程之资源 4.5 术语表
查看>>
菜鸟网络算法专家朱礼君:为你的淘宝订单选外箱的是人工智能 | CCF-GAIR 2017
查看>>
CMU教授金出武雄演讲:户外机器人系统 | CCF-GAIR 2017
查看>>
未来3年内25G将成数据中心主流网络
查看>>
《云计算:原理与范式》一1.3 云计算的架构与类型
查看>>
Strategy Analytics:视频监控是安防系统成功的关键
查看>>
四家企业联合发起 OPEN AI LAB,听听余凯等大佬怎么说
查看>>
永不晕车的法子, 快告诉你身边晕车的人!
查看>>
《游戏设计师修炼之道:数据驱动的游戏设计》一第2章
查看>>
php在客户端禁用cookie时让session不失效的解决方法
查看>>
以色列移动社交支付应用PayKey获600万美元A轮融资
查看>>
数据中心安全概论
查看>>
Facebook公司计划将其沃斯堡数据中心拓展三倍规模
查看>>