2012 #1 Saving Princess claire_
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
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
Sample Input
Y*C
1 3 2
Y#C
1 5 2
YP#PC
Sample Output
Damn teoy!
0
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
const int inf=0x3f3f3f3f; struct Node
{
int x;
int y;
};
char mp[][];
int d[][],sx,sy,gx,gy,nump;
int dx[]={,,-,},dy[]={,,,-};
Node P[]; int main()
{
int n,m,c;
int i,j;
while(scanf("%d %d %d",&n,&m,&c)!=EOF)
{
nump=;
getchar();
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
d[i][j]=inf;
scanf("%c",&mp[i][j]);
if(mp[i][j]=='Y')
sx=i,sy=j;
if(mp[i][j]=='C')
gx=i,gy=j;
if(mp[i][j]=='P')
{
nump++;
P[nump].x=i,P[nump].y=j;
}
}
getchar();
} queue<Node> que;
while(que.size()) que.pop();
Node s;
s.x=sx,s.y=sy;
que.push(s);d[sx][sy]=; while(que.size())
{
Node now=que.front(),nex;
/*for(i=1;i<=m;i++)
printf("%d ",d[1][i]);
printf("\n");
printf("%d\n",now.y);*/
que.pop(); for(i=;i<;i++)
{
int nx=now.x+dx[i],ny=now.y+dy[i];
if(<=nx && nx<=n && <=ny && ny<=m && mp[nx][ny]!='#')
{
int value=d[now.x][now.y];
if(mp[nx][ny]=='*')
value++;
if(mp[nx][ny]=='P')
{
for(j=;j<=nump;j++)
{
if(value<d[P[j].x][P[j].y])
{
que.push(P[j]);
d[P[j].x][P[j].y]=value;
}
}
}
else
{
if(value<d[nx][ny])
{
//printf("%d %d %d\n",now.x,ny,value);
nex.x=nx,nex.y=ny;
que.push(nex);
d[nx][ny]=value;
}
}
}
}
} if(d[gx][gy]==inf)
printf("Damn teoy!\n");
else
printf("%d\n",d[gx][gy]*c);
}
return ;
}
/*
1 7 5
PY**C*P
*/
2012 #1 Saving Princess claire_的更多相关文章
- hdu----(4308)Saving Princess claire_(搜索)
Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- HDU 4308 BFS Saving Princess claire_
原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...
- Saving Princess claire_(hdu 4308 bfs模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...
- hdu 4308 Saving Princess claire_ BFS
为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...
- HDU 4308 Saving Princess claire_(简单BFS)
求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...
- BFS(最短路) HDOJ 4308 Saving Princess claire_
题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...
- ZOJ 3369 Saving Princess
Saving Princess Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...
- UESTC 1811 Hero Saving Princess
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/11104265 题目链接 :http://222.197.181.5/proble ...
随机推荐
- Power Gating的设计(模块二)
针对lower power的验证,由cpf/upf来建模,包括: 1)power gating的功能模型(在power gate之后将output force为x) 2)isolation功能模型: ...
- linux上操作mysql数据库
sudo /etc/init.d/mysql start启动mysql netstat -lntup|grep 3306查看端口3306 grant all privileges on *.* to ...
- Linux的视频编程(V4L2编程)【转】
本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11472073 一.什么是video4linuxVideo4linux2(简称V4L2), ...
- Git 使用规范流程
Git教程:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 团队开发中,遵循一个合 ...
- printf,sprintf,vsprintf 区别【转】
转自:http://blog.csdn.net/anye3000/article/details/6593551 有C语言写作历史的程序员往往特别喜欢printf 函数.即使可以使用更简单的命令(例如 ...
- MyISAM表杂记实验
一.本文说明 由于刚学mysql所以动手做了一些实验. 二.实验内容 1.验证MyISAM有AUOT_INCREMENT coloumn功能 ----在这里是对现有表t,增加一个主键----mysql ...
- 11、Jsp加强/EL表达式/jsp标签
1 Jsp基础回顾 Jsp基础 1)Jsp的执行过程 tomcat服务器完成:jsp文件->翻译成java文件->编译成class字节码文件-> 构造类对象-> 调用方法 to ...
- ecshop订单打印页显示商品缩略图和序号
ecshop订单打印页显示商品缩略图和序号 订单打印页显示商品缩略图,在论坛没找到适合2.7.2相关的文章,特意贴上来给大家研究一下.1.找到 $sql = "SELECT o.*, IF( ...
- 每日一九度之 题目1031:xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6870 解决:4302 题目描述: 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...
- 求两个数的最大公约数(Java)
获得两个随机数(100以内),并放入数组中 public int[] getTwoRandom(){ int[] t = new int[2]; Random rand = new Random(); ...