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 ...
随机推荐
- thinkphp3.2 实现二级导航和高亮显示
一.控制器代码如下: public function index(){ //高亮显示 $action = CONTROLLER_NAME."/".ACTION_NAME; $thi ...
- 【小程序+thinkphp5】 用户登陆,返回第三方session3rd
服务器环境: centos7 php7.0 准备工作: 注册小程序,并获取 appid .appsecret 下载微信解密算法sdk : https://mp.weixin.qq.com/debu ...
- 【转】C++可变参数列表处理宏va_list、va_start、va_end的使用
VA_LIST是在C语言中解决变参问题的一组宏他有这么几个成员: 1)va_list型变量: #ifdef _M_ALPHA typedef struct{ char* a0; /*po ...
- 【大数据系列】hadoop集群设置官方文档翻译
Hadoop Cluster Setup Purpose Prerequisites Installation Configuring Hadoop in Non-Secure Mode Config ...
- SSL延迟有多大?
http://www.ruanyifeng.com/blog/2014/09/ssl-latency.html 作者: 阮一峰 日期: 2014年9月24日 据说,Netscape公司当年设计SSL协 ...
- 算法题目-记hulu失败的实习面试
1.对于数组A[0,1,2,3,4,...,k],求得0<=i < j < k,且使得A[j] - A[i]为最大值. 最简单也最容易想到的搜索两遍,即可得到答案.i的位置从起始至倒 ...
- Razon模板
转:http://www.cnblogs.com/huangxincheng/p/3644313.html 随笔- 119 文章- 0 评论- 2039 抛弃NVelocity,来玩玩Razor ...
- Pyqt图标下载网站
下载地址: https://www.easyicon.net/ 1.程序中图标建议使用32x32的PNG格式. 2.pyinstaller打包中图标建议使用32x32的ICO格式.
- 7.24 IO多路复用和协程代码笔记
1. 复习 # !/usr/bin/env python # !--*--coding:utf-8 --*-- # !@Time :2018/7/23 11:49 # !@Author TrueNew ...
- EDA优势
1.提供明确的表述性业务概念 在某些场景下,一个业务概念会被多个流程更改,如果此属性逻辑发生变化,其他关联的流程将无法知晓,导致bug产生 如:出于性能或其他因素考虑下,为A表增加一个冗余字段,操作A ...