hdu----(4308)Saving Princess claire_(搜索)
Saving Princess claire_
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2354 Accepted Submission(s): 843
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.
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.
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.)
Y*C
1 3 2
Y#C
1 5 2
YP#PC
Damn teoy!
0
#include<cstring>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std; const int maxn=;
int cc,rr,cost;
char str[maxn][maxn];
struct node {
int x,y;
int val;
};
vector <node> pot; int dir[][]={{,},{,},{-,},{,-}};
node st,en;
queue<node>seek;
node tem,qq;
vector<node>::iterator it;
int main(){ //freopen("test.in","r",stdin);
while(scanf("%d%d%d",&rr,&cc,&cost)!=EOF){ pot.clear();
vector< vector<node> > map(rr+);
for(int i=;i<rr+;i++)
map[i].resize(cc+);
for(int i=;i<rr;i++){
scanf("%s",str[i]);
for(int j=;j<cc;j++){
map[i][j]=(node){i,j,};
if(str[i][j]=='P'){
pot.push_back((node){i,j,});
}
if(str[i][j]=='Y')
st=(node){i,j,};
if(str[i][j]=='C'){
en=(node){i,j,-};
map[i][j]=(node){i,j,-};
}
}
}
//bfs();
seek.push(st);
while(!seek.empty()){
tem=seek.front();
seek.pop();
for(int i=;i<;i++){
qq=(node){tem.x+dir[i][],tem.y+dir[i][],};
if(qq.x>=&&qq.x<rr&&qq.y>=&&qq.y<cc&&str[qq.x][qq.y]!='#'){
if(str[qq.x][qq.y]!='C'){
if(str[qq.x][qq.y]=='P'){
str[qq.x][qq.y]='#';
if(map[qq.x][qq.y].val==||map[qq.x][qq.y].val>map[tem.x][tem.y].val)
map[qq.x][qq.y].val=map[tem.x][tem.y].val;
if(pot.size()!=){
for(it=pot.begin();it<pot.end();it++)
if((*it).x==qq.x&&(*it).y==qq.y) break;
pot.erase(it);
}
if(pot.size()!=){
for(it=pot.begin();it<pot.end();it++){
map[(*it).x][(*it).y].val=map[qq.x][qq.y].val;
seek.push((map[(*it).x][(*it).y]));
str[(*it).x][(*it).y]='#';
}
}else seek.push(map[qq.x][qq.y]); }
else if(map[qq.x][qq.y].val==||map[qq.x][qq.y].val>tem.val+cost){
map[qq.x][qq.y].val=tem.val+cost;
seek.push(map[qq.x][qq.y]);
}
}
else
if(map[qq.x][qq.y].val==-||map[qq.x][qq.y].val>tem.val)
{
map[qq.x][qq.y].val=tem.val;
}
}
}
}
if(map[en.x][en.y].val==-)
printf("Damn teoy!\n");
else
printf("%d\n",map[en.x][en.y].val);
}
return ;
}
hdu----(4308)Saving Princess claire_(搜索)的更多相关文章
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- hdu 4308 Saving Princess claire_ BFS
为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...
- HDU 4308 Saving Princess claire_(简单BFS)
求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...
- BFS(最短路) HDOJ 4308 Saving Princess claire_
题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...
- HDU 4308 BFS Saving Princess claire_
原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...
- Saving Princess claire_(hdu 4308 bfs模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...
- 2012 #1 Saving Princess claire_
Saving Princess claire_ Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- hdu 3037 Saving Beans(组合数学)
hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数. 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m.可是n,m非常大,所以 ...
随机推荐
- FRM-10001, FRM-10002, FRM-10003 Oracle Form Builder Error Solution
These errors occurred usually due to forms connection problem or some internal problem, the solution ...
- 配置Servlet3.0的方式和注意事项!
- 09.VMWare虚拟机copy后网卡不是eth0解决办法
0.如果VM虚拟机已经复制了,网卡已经不是eth0了,看下面1--->步骤,如果还没复制将要复制,只看1就行 点击I copy it.这时虚拟机会在开机时检查是否次网卡无力地址已经存在, ...
- TCP的流量控制和拥塞控制
1.TCP的流量控制 一般说来,我们总是希望数据传输的更快一些.但如果发送方吧数据发送的过快,接收方就可能来不及接收,就会造成数据的丢失.所谓的流量控制就是让发送方的发送速率不要太快,要让接收方来的及 ...
- .NET在后置代码中输入JS提示语句(背景不会变白)
来源:http://niunan.iteye.com/blog/248256 Page.ClientScript.RegisterStartupScript(Page.GetType(), " ...
- NOJ 1063 生活的烦恼
描述 生活的暑假刚集训开始,他要决心学好字典树,二叉树,线段树和各种树,但生活在OJ上刷题的时候就遇到了一个特别烦恼的问题.那当然就是他最喜欢的二二叉树咯!题目是这样的:给你一颗非空的二叉树,然后再给 ...
- oracle的基本概念
一·简介 1)数据库(DataBase) 用于存放数据,管理数据的存储仓库,是有效组织在一起的数据集合. 2)常用数据库软件 大型数据库:Oracle 中小型数据库:Mysql MySQL 3)RDB ...
- HDU 1394
单点,利用线段树解题,看到数据大小一定要敏感,说不定就是暗藏的解题思路 #include <stdio.h> #define lson l,mid,id<<1 #define ...
- HDU5785 manacher+差分数组
用manacher算法O(n)求出所有的回文半径.有了回文半径后,就可以求出L[i]表示以i结尾的回文串的起始位置的和R[i]表示以i起始的回文串的结尾位置的和,然后就可以求出答案了,这里要注意奇偶长 ...
- 关于css3的自定义字体
css3的@font-face属性打破了中文页面字体一成不变的格局,但今天本菜在用的时候并不那么爽.开始各种引用外部ttf文件失败.下了300M+的字体文件,苦逼的试了一下午.终于有一个ttf引用成功 ...