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
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
2012 Multi-University Training Contest 1
拥有传送们的搜索.....wa了一下午....(/ □ )
终于搞成AC了....
代码:
1 #include<cstring>
2 #include<cstdio>
3 #include<queue>
4 #include<vector>
5 using namespace std;
6
7 const int maxn=5003;
8 int cc,rr,cost;
9 char str[maxn][maxn];
10 struct node {
11 int x,y;
12 int val;
13 };
14 vector <node> pot;
15
16 int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
17 node st,en;
18 queue<node>seek;
19 node tem,qq;
20 vector<node>::iterator it;
21 int main(){
22
23 //freopen("test.in","r",stdin);
24 while(scanf("%d%d%d",&rr,&cc,&cost)!=EOF){
25
26 pot.clear();
27 vector< vector<node> > map(rr+10);
28 for(int i=0;i<rr+10;i++)
29 map[i].resize(cc+10);
30 for(int i=0;i<rr;i++){
31 scanf("%s",str[i]);
32 for(int j=0;j<cc;j++){
33 map[i][j]=(node){i,j,0};
34 if(str[i][j]=='P'){
35 pot.push_back((node){i,j,0});
36 }
37 if(str[i][j]=='Y')
38 st=(node){i,j,0};
39 if(str[i][j]=='C'){
40 en=(node){i,j,-1};
41 map[i][j]=(node){i,j,-1};
42 }
43 }
44 }
45 //bfs();
46 seek.push(st);
47 while(!seek.empty()){
48 tem=seek.front();
49 seek.pop();
50 for(int i=0;i<4;i++){
51 qq=(node){tem.x+dir[i][0],tem.y+dir[i][1],0};
52 if(qq.x>=0&&qq.x<rr&&qq.y>=0&&qq.y<cc&&str[qq.x][qq.y]!='#'){
53 if(str[qq.x][qq.y]!='C'){
54 if(str[qq.x][qq.y]=='P'){
55 str[qq.x][qq.y]='#';
56 if(map[qq.x][qq.y].val==0||map[qq.x][qq.y].val>map[tem.x][tem.y].val)
57 map[qq.x][qq.y].val=map[tem.x][tem.y].val;
58 if(pot.size()!=0){
59 for(it=pot.begin();it<pot.end();it++)
60 if((*it).x==qq.x&&(*it).y==qq.y) break;
61 pot.erase(it);
62 }
63 if(pot.size()!=0){
64 for(it=pot.begin();it<pot.end();it++){
65 map[(*it).x][(*it).y].val=map[qq.x][qq.y].val;
66 seek.push((map[(*it).x][(*it).y]));
67 str[(*it).x][(*it).y]='#';
68 }
69 }else seek.push(map[qq.x][qq.y]);
70
71 }
72 else if(map[qq.x][qq.y].val==0||map[qq.x][qq.y].val>tem.val+cost){
73 map[qq.x][qq.y].val=tem.val+cost;
74 seek.push(map[qq.x][qq.y]);
75 }
76 }
77 else
78 if(map[qq.x][qq.y].val==-1||map[qq.x][qq.y].val>tem.val)
79 {
80 map[qq.x][qq.y].val=tem.val;
81 }
82 }
83 }
84 }
85 if(map[en.x][en.y].val==-1)
86 printf("Damn teoy!n");
87 else
88 printf("%dn",map[en.x][en.y].val);
89 }
90 return 0;
91 }
- Android解析ClassLoader(二)Android中的ClassLoader
- 近期开发中遇到的问题总结
- Apache Spark中的决策树
- 数据结构是哈希表(hashTable)
- 【翻译】在Visual Studio中使用Asp.Net Core MVC创建你的第一个Web API应用(一)
- 基于JQuery EasyUI的WebMVC控件封装(含源码)
- Android系统源码分析-JNI
- EntityFrameWork实现部分字段获取和修改(含源码)
- 基于Ado.Net的日志组件
- Do you kown Asp.Net Core -- 配置Kestrel端口
- 【翻译】在Visual Studio中使用Asp.Net Core MVC创建第一个Web Api应用(二)
- 微信快速开发框架(一)-- 对微信公众平台开发的消息处理
- 微信快速开发框架(二) -- 快速开发微信公众平台框架---简介
- LayoutInflater 布局渲染工具原理分析
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Maven构建项目速度太慢的解决办法
- 基于kubernetes Api完成更新镜像版本
- 代码覆盖率是什么?如何查看?
- 3分钟短文 | Laravel 注册全局助手函数的2种方式
- 通过案例学Python之定义函数类
- 3分钟短文 | Laravel blade模板里优雅地定义PHP变量
- MySQL 日期时间类型怎么选?千万不要乱用!
- InnoDB存储引擎简介
- git改错分支的补救方法:git stash暂存
- 快速学习-Skywalking原理
- 快速学习-Skywalking常用插件
- 快速学习-Skywalking-MySql调用监控
- 我为何弃用Jetpack的App Startup?
- 快速学习-Skywalking的RPC调用-Dubbo的最佳实践
- Spring Cloud Gateway开发的几个要点