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非常大,所以 ...
随机推荐
- 如何使用NUnit
http://www.c-sharpcorner.com/UploadFile/84c85b/nunit-with-C-Sharp/ 从github上下载安装包 NUnit.3.4.1.msi htt ...
- 通过NuGet获取sqlite对应的.net的dll
https://www.nuget.org/packages/System.Data.SQLite/ 直接在Package Manager Console中执行命令,会自动安装依赖项的 Install ...
- ggplot2 legend图例的修改
ggplot2中的legend包括四个部分: legend.tittle, legend.text, legend.key, legend.backgroud.针对每一部分有四种处理方式: eleme ...
- weblogic解密工具
import org.bouncycastle.jce.provider.BouncyCastleProvider; import sun.misc.BASE64Decoder; import jav ...
- [Effective Java]第六章 枚举和注解
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- 转载java源代码阅读方法
刚才在论坛不经意间,看到有关源码阅读的),不禁又有一种激动. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比方吧,如果你从来没有学过Java,或是任何一门编程语言 ...
- varchar(10)与nvarchar(10)有什么区别
前者是非unicode型,存储字符按1个算(内部空间存储占1字节),存储汉字的话按2个算, 就是可以存10个字符或者5个汉字 后者是unicode型,存储什么都是按1个算(内部空间存储占2字节), 就 ...
- [转载] 数据库分析手记 —— InnoDB锁机制分析
作者:倪煜 InnoDB锁机制常常困扰大家,不同的条件下往往表现出不同的锁竞争,在实际工作中经常要分析各种锁超时.死锁的问题.本文通过不同条件下的实验,利用InnoDB系统给出的各种信息,分析了锁的工 ...
- 简单的php性能注意点
什么情况,可能遇到性能问题: 1.php语法使用的不恰当 2.使用php语言做了它不擅长做的事 3.用php语言连接的服务不给力 4.php自身的短板 5.我也不知道的问题 一般情况:php性能问题不 ...