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非常大,所以 ...
随机推荐
- UE4编程之C++创建一个FPS工程(二)角色网格、动画、HUD、子弹类
转自:http://blog.csdn.net/u011707076/article/details/44243103 紧接上回,本篇文章将和大家一同整理总结UE4关于角色网格.动画.子弹类和HUD的 ...
- sqlite中的自增主键
http://stackoverflow.com/questions/8519936/sqlite-autoincrement-primary-key-questions I'm not sure w ...
- hihoCoder太阁最新面经算法竞赛17
比赛链接:http://hihocoder.com/contest/hihointerview26 A.排序后枚举两个点,确定一个矩形后二分剩下两个点. #include <bits/stdc+ ...
- 数据词典与ABAP类型映射
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- 加载xib文件
// Test.xib --编译--> Test.nib // 方式1 NSArray *objs = [[NSBundle mainBundle] loadNibNamed:@"Te ...
- 历史命令history
历史命令在用户注销之后会保存在用户家目录下的-/.bash_history中 history #查看系统中实时缓存的历史命令,与.bash_history中的内容并不完全相同 history -c # ...
- FineReport: 参数为空选出全部值(按条件查询,空条件时直接过滤,不进行查询。。)
在Java报表软件FineReport中,选择特定的参数(如下图中的姓名.身份证号等)后,会返回我们要查询的数据,然而假如没有输入参数值,我们却仍需要返回数据时该怎样处理呢?应该过滤掉这个条件,不按这 ...
- win 8 pip install 或者 pycharm 安装 paramiko 报错
这是安装时报错的最后几行 creating build\temp.win-amd64-3.5\Release\build creating build\temp.win-amd64-3.5\Relea ...
- Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array 分块
E. Lucky Array time limit per test 4 seconds memory limit per test 256 megabytes input standard inpu ...
- XAF应用开发教程(二)业务对象模型之简单类型属性
使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D. 不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息.我们只做个简单 的客户信息来了解一下XAF ...