Saving Princess claire_(hdu 4308 bfs模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4308
Saving Princess claire_
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2305 Accepted Submission(s): 822
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.)
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n,m,V;
char map[][];
int v[][];
struct node
{
int x,y,ans;
}q[];
int jx[]={,-,,};
int jy[]={,,,-};
void bfs(int xx,int yy)
{
int e=;
int s=;
memset(v,,sizeof(v));
struct node t,f;
t.x=xx;
t.y=yy;
t.ans=;
v[t.x][t.y]=;
q[e++]=t;
while(s<e)
{
t=q[s++];
if(map[t.x][t.y]=='C')
{
printf("%d\n",t.ans);
return ;
}
for(int i=;i<;i++)
{
f.x=t.x+jx[i];
f.y=t.y+jy[i];
if(f.x>=&&f.x<n&&f.y>=&&f.y<m&&map[f.x][f.y]!='#'&&v[f.x][f.y]==)
{
if(map[f.x][f.y]=='*')
{
f.ans=t.ans+V;
q[e++]=f;
v[f.x][f.y]=;
}
else if(map[f.x][f.y]=='C')
{
f.ans=t.ans;
q[e++]=f;
v[f.x][f.y]=;
}
else if(map[f.x][f.y]=='P')
{
for(int j=;j<n;j++)
{
for(int k=;k<m;k++)
{
if(map[j][k]=='P')
{
f.ans=t.ans;
f.x=j;
f.y=k;
q[e++]=f;
v[f.x][f.y]=;
}
}
}
}
}
}
}
printf("Damn teoy!\n");
return ;
}
int main()
{
int xx,yy;
while(scanf("%d%d%d",&n,&m,&V)!=EOF)
{
for(int i=;i<n;i++)
scanf("%*c%s",map[i]);
int j;
for(int i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(map[i][j]=='Y')
{
xx=i;
yy=j;
break;
}
}
if(j!=m) break;
}
bfs(xx,yy);
}
return ;
}
Saving Princess claire_(hdu 4308 bfs模板题)的更多相关文章
- HDU 4308 Saving Princess claire_(简单BFS)
求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...
- HDU 4308 BFS Saving Princess claire_
原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- 2012 #1 Saving Princess claire_
Saving Princess claire_ Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu----(4308)Saving Princess claire_(搜索)
Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- hdu1242 又又又是逃离迷宫(bfs模板题)
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1242/ 这次的迷宫是有守卫的,杀死一个守卫需要花费1个单位的时间,所以以走的步数为深度,在每一层进行搜索,由于走 ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- HDU 2138 Miller-Rabin 模板题
求素数个数. /** @Date : 2017-09-18 23:05:15 * @FileName: HDU 2138 miller-rabin 模板.cpp * @Platform: Window ...
随机推荐
- Python学习(24):Python面向对象(2)
转自 http://www.cnblogs.com/BeginMan/p/3191037.html 一.类 类就是一个数据结构,封装了数据和操作. 类的声明与函数的声明十分类似: class newC ...
- 动力学仿真引擎ODE的学习笔记,C#演示(一)
®版权声明:本文为博主原创文章,未经博主允许不得转载. 一.ODE介绍与平台搭建. 接触到动力学仿真引擎, 是因为笔者的一款PLC仿真软件需要3D仿真.我需要达到的效果是,以3D方式构建出工控行业中常 ...
- Android 请求运行时权限
写文件到sd卡中,会报权限问题,需要动态申请申请运行时权限 1. MainActivity.java public class MainActivity extends Activity { priv ...
- Elasticsearch学习之SearchRequestBuilder的query类型
1. 分词的时机 对于ES来讲,可以对文档的内容进行分词(前提是设置了analyzed),也可以对输入的搜索词进行分词.对输入的搜索词进行分词时需要看下使用的什么类型的query.不同的query可能 ...
- 题目1002:Grading(题目背景基于高考打分的简单判断)
题目链接:http://ac.jobdu.com/problem.php?pid=1002 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- [VS]VS2010如何使用Visual Studio Online在线服务管理团队资源(在线TFS)
前言 Visual Studio Online,也就是以前的Team Foundation Service,从名字可以看出这是一个团队资源管理服务.在微软的云基础架构中运行,无需安装或配置任何服务器, ...
- PHPStorm 注册码&主题皮肤
JetBrains PhpStorm 注册方法: 用浏览器打开 http://idea.lanyus.com/ 点击页面中的“获得注册码” 然后打开PhpStorm,在注册时切换至Activation ...
- Mysql----数据备份、pymysql模块
一 IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 掌握: #1. 测试+链接 ...
- 为VS定制一个自己的代码生成器 - 自定义工具开发
自定义工具开发 为VS定制一个自己的代码生成器 如何在Visual Studio中开发自己的代码生成器插件 你必须懂的 T4 模板:深入浅出 Regasm组件注册工具使用方法 Regasm 注册C# ...
- split和strip的使用
我觉得都可以进行分隔,但最大的不同就是一个返回list,一个返回字符串 s1 = 'deng ye xun' s1.split() Out[8]: ['deng', 'ye', 'xun'] s1.s ...