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. Cheatsheet: 2014 04.01 ~ 04.30

    Java 115 Java Interview Questions and Answers – The ULTIMATE List 3 Good Reasons to Avoid Arrays in ...

  2. WebRTC的学习(二)

    英文原文的链接地址为:https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Overview WebRTC是由一些关联的API和协议一 ...

  3. PythonOCC 3D图形库学习—创建立方体模型

    Open CASCADE(简称OCC)平台是是一个开源的C++类库,OCC主要用于开发二维和三维几何建模应用程序,包括通用的或专业的计算机辅助设计CAD系统.制造或分析领域的应用程序.仿真应用程序或图 ...

  4. I2C总线信号时序总结

    I2C总线信号时序总结 总线空闲状态  I2C总线总线的SDA和SCL两条信号线同时处于高电平时,规定为总线的空闲状态.此时各个器件的输出级场效应管均处在截止状态,即释放总线,由两条信号线各自的上拉电 ...

  5. 用Spring MVC开发简单的Web应用

    这个例子是来自于Gary Mak等人写的Spring攻略(第二版)第八章Spring @MVC中的一个例子,在此以学习为目的进行记录. 问题:想用Spring MVC开发一个简单的Web应用, 学习这 ...

  6. win7删除IE图标方法-----(注册表找不到对应的IE项)

    删除个IE图标费了半天事,硬是找不到网上说的那个 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desk ...

  7. Sql 行转列问题总结

    行转列问题总结 1.行转列 ---1.最简单的行转列/* 问题:假设有张学生成绩表(tb)如下:姓名 课程 分数张三 语文 74张三 数学 83张三 物理 93李四 语文 74李四 数学 84李四 物 ...

  8. Memcached通用类(基于Memcached Client Library)

    分享下自己编写的Memcached通用类.欢迎大家帮忙指点下哈~ 使用的是.NET memcached client library 客户端+Memcached Providers using Sys ...

  9. c++ vector 简单实现。

    第二次修改: 1)熟悉基本的模板编程,头文件和定义必须放到一起. 2)熟悉内存管理模板类 allocator<T>. 1.使用标准库的内存管理类 allocator<T> 代替 ...

  10. c point

    a[i] 与 *(a+i) 是等价的. 事实上在计算a[i]的值时,c语言首先将前者转换为后者形式, 而且,通常而言,用指针编写的程序要比用数组下标编写的程序执行速度快,(为什么?) 因此,应该尽量用 ...