博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4308 Saving Princess claire_(BFS+优先队列)
阅读量:4205 次
发布时间:2019-05-26

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

Saving Princess claire_

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2771    Accepted Submission(s): 1002


Problem 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 3Y*C1 3 2Y#C1 5 2YP#PC
 

Sample Output
3Damn teoy!0
 

Author
BUPT
 

Source
问题描述
公主claire_被囚禁在一个迷宫的大恶魔怪物(GDM)teoy。
出于愤怒,小王子ykwd决定闯入迷宫营救他可爱的公主。
迷宫可以被描述为r行和c列的矩阵,其中具有网格,诸如“Y”,“C”,“*”,“#”和“P”。每个网格都与其上,下,左和右网格相连。
只有一个“Y”意味着王子ykwd突破迷宫的初始位置。
只有一个“C”表示公主claire_被判入狱的地方。
在迷宫中可能有许多'*',代表相应的网格可以通过一定的金额的成本,因为GDM teoy已经设置收费站。
由'#'表示的网格意味着你不能通过它。
据说,由于GDM teoy喜欢撒尿和狗屎到处,这个网格不幸被他的丑陋行为损坏。
'P'表示它是一个传输端口,在迷宫中可能有一些。这些端口(如果存在)彼此连接,王子ykwd可以从其中一个跳到另一个。
他们说,以前有一些收费站,但他们爆炸(肯定是他们不存在),因为GDM teoy的野蛮行为(尿尿和屎!),因此一些虫洞变成了存在,你知道以下事情。记住,王子ykwd有他的神秘的力量,他可以选择他的方式在虫洞,即使他可以选择忽略虫洞。
虽然王子ykwd深深地爱公主claire_,他是如此的意思,他不想花太多的钱在迷宫。然后他转向你,伟大的工人谁爱移动砖,帮助,他希望你能计算他需要带回他的公主的最低金钱。
 
输入
多个案件(不超过五十个。)
第一行包含3个整数,r,c和cost。 'r','c'和'cost'如上所述(0 <r * c <= 5000,货币在(0,10000]的范围内)
然后一个r * c字符矩阵与'P'不超过所有网格的数量的10%,我们承诺,将没有收费站,王子和公主存在。
 
输出
一行带有整数,表示最小成本。如果王子王不能救他的公主,不管他做什么,然后输出“Damn teoy!”(详见示例)。

题意:从Y走到C,#代表不能走,走*的话要花费C元,P是传送门可以到达任意一个P,问最小花费

思路:直接优先队列模拟一下就行,BFS搜一下,P直接记录,遇到了就判断它能到达的点能不能走就行了

////  main.cpp//  dfs-bfs搜索////  Created by liuzhe on 16/8/10.//  Copyright © 2016年 my_code. All rights reserved.//#include 
#include
#include
#include
#include
#include
using namespace std;//hdu 4308const int inf = 0x3f3f3f3f;const long long INF = 0x3f3f3f3f3f3f3f3fll;const int maxn = 5005;int n,m,k,sx,sy,ex,ey;int dir[4][2] = { {0,1},{0,-1},{1,0},{-1,0}};bool vis[maxn][maxn];char str[maxn][maxn];struct edge{ int x,y,step,flag; friend bool operator<(edge n1,edge n2) { return n1.step>n2.step; }};struct pos{ int x,y; pos(int a,int b):x(a),y(b) { }};vector
G;int bfs(){ priority_queue
que; edge c,ne; memset(vis,0,sizeof(vis)); c.x = sx; c.y = sy; c.step = 0; vis[c.x][c.y] = 1; que.push(c); while(!que.empty()) { c = que.top(); que.pop(); if(c.x==ex&&c.y==ey) return c.step; if(str[c.x][c.y] == 'P') { int len = G.size(); for(int ii=0;ii
n-1||yy<0||yy>m-1||str[xx][yy]=='#') continue; if(vis[xx][yy]) continue; ne.x = xx; ne.y = yy; ne.step = c.step; if(str[xx][yy]=='*') ne.step+=k; vis[ne.x][ne.y] = 1; que.push(ne); } } return -1;}int main(){ while(scanf("%d%d%d",&n,&m,&k)!=-1) { G.clear(); for(int i=0;i

转载地址:http://fpali.baihongyu.com/

你可能感兴趣的文章
JavaWeb 报错The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml
查看>>
JavaWeb getParameter和getAttribute的区别
查看>>
JavaWeb jsp内置对象与servlet对应关系
查看>>
Spring 之依赖注入DI
查看>>
Spring 注解总结
查看>>
Spring 面向切面编程AOP
查看>>
数据库优化 SQL语句优化
查看>>
Spring 各个jar包的作用
查看>>
SpringMVC 出现ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
查看>>
SpringMVC 过滤器HiddenHttpMethodFilter
查看>>
SpringMVC 返回json数据报错IllegalArgumentException: No converter found for return value of type:xxx
查看>>
SpringMVC 基本配置文件
查看>>
Velocity 模板出现NestedIOException: Cannot find Velocity template for URL [layout.vm]
查看>>
Velocity 模板基本用法
查看>>
SpringMVC 使用总结
查看>>
Mybatis 出现Mapped Statements collection does not contain value for xxx
查看>>
Mybatis 解决字段名与实体类属性名不相同的冲突
查看>>
Mybatis Generator最完整配置详解
查看>>
Mybatis 一级缓存和二级缓存
查看>>
Hibernate 出现Unsupported major.minor version 52.0 [duplicate]
查看>>