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

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 3
Y*C

1 3 2
Y#C

1 5 2
YP#PC

 
Sample Output
3
Damn teoy!
0
 
Author
BUPT
 
Source
 
拥有传送们的搜索.....wa了一下午....(/ □ \)
终于搞成AC了....
代码:
 #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_(搜索)的更多相关文章

  1. hdu 4308 Saving Princess claire_

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...

  2. hdu 4308 Saving Princess claire_ BFS

    为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...

  3. HDU 4308 Saving Princess claire_(简单BFS)

    求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...

  4. BFS(最短路) HDOJ 4308 Saving Princess claire_

    题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...

  5. HDU 4308 BFS Saving Princess claire_

    原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...

  6. Saving Princess claire_(hdu 4308 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...

  7. 2012 #1 Saving Princess claire_

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

  8. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  9. hdu 3037 Saving Beans(组合数学)

    hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数. 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m.可是n,m非常大,所以 ...

随机推荐

  1. CodeForces 432B Football Kit

     Football Kit Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Subm ...

  2. C#日志写入

    /// <summary> /// 写日志,指定日志文件 /// </summary> /// <param name="File"></ ...

  3. Vi编辑器下使用分屏显示【已自己验证所有】

    :new 水平分割出一个新窗口 :vnew,:vne 垂直分割出一个新窗口 :new+文件路径/文件名; 在新的水平分屏中 载入/新建 文件.[文件存在则载入,不存在则在指定的路径新建,下同] :vn ...

  4. CANopen笔记1

    CAN现场总线只定义了OSI网络模型的第一层(物理层) 和第二层(数据链路层) ,而这两层一般已被CAN硬件完全实现了.由于没有规定应用层,本身并不完整,需要一个高层协议来定义CAN报文中的11/29 ...

  5. 序列化、反序列化(实体类或要序列化的对象类必须实现Serializable接口)

    package com.phone.shuyinghengxie; import java.io.Serializable; /* 一个类的对象要想序列化成功,必须满足两个条件: 该类必须实现 jav ...

  6. JS 实现新浪微博, QQZone 等的分享

    <script type="text/javascript">window.pageConfig = { compatible: true,searchType: 1 ...

  7. poj3667【线段树】/【类似权值线段树写法】

    题意:n个空房间.两种操作:1.选择最小的连续D个房间入住,并输出这连续D个房间的最小标号.2.将某个区间内的房间全部退房. #include <cstdio> #include < ...

  8. Oracle分析函数的项目实践实例

    SELECT * FROM SSE2_FLOW_EXPENSE T1 JOIN (SELECT SFEL.*, ROW_NUMBER() OVER(PARATITION BY SFEL.FE_EXPE ...

  9. Oracle数据库内置函数

    --ORACLE内置函数:单行函数,集合函数--1.绝对值,取余,判断数据正负函数,SELECT ABS(100),ABS(-100),ABS('100') FROM DUAL;SELECT MOD( ...

  10. IIS Express简介

    当前程序员只能通过下面两种Web服务器之一来开发和测试ASP.NET网站程序: 1. Visual Studio自带的ASP.NET开发服务器(webdev.exe). 2. Windows自带的II ...