HDU3345广搜 (P,E,T,#)
In this game, there is an N * M battle map, and every player has his own Moving Val (MV). In each round, every player can move in four directions as long as he has enough MV. To simplify the problem, you are given your position and asked to output which grids you can arrive.

In the map:
'Y' is your current position (there is one and only one Y in the given map).
'.' is a normal grid. It costs you 1 MV to enter in this gird.
'T' is a tree. It costs you 2 MV to enter in this gird.
'R' is a river. It costs you 3 MV to enter in this gird.
'#' is an obstacle. You can never enter in this gird.
'E's are your enemies. You cannot move across your enemy, because once you enter the grids which are adjacent with 'E', you will lose all your MV. Here “adjacent” means two grids share a common edge.
'P's are your partners. You can move across your partner, but you cannot stay in the same grid with him final, because there can only be one person in one grid.You can assume the Ps must stand on '.' . so ,it also costs you 1 MV to enter this grid.
Then T cases follow:
Each test case starts with a line contains three numbers N,M and MV (2<= N , M <=100,0<=MV<= 65536) which indicate the size of the map and Y's MV.Then a N*M two-dimensional array follows, which describe the whole map.
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
char map1[105][105],ans[105][105];
int m,n,mv;
int startx,starty;
int count1[105][105];
int NEXT[4][2]={1,0,0,-1,-1,0,0,1};
struct node
{
int x;
int y;
int s;
}q1,q2;
queue<node>qu;
int calulate(int x1,int y1,int v)
{
int tx,ty,ret;
if( map1[x1][y1]=='T')
ret=v-2;
else if( map1[x1][y1]=='R')
ret=v-3;
else
ret=v-1;
for(int i=0;i<=3;i++)
{
tx=x1+NEXT[i][0];
ty=y1+NEXT[i][1];
if(tx<1||tx>m||ty<1||ty>n)
continue;
if( map1[tx][ty]=='E')
{
if(ret>0)
return 0;
else
return ret;
}
}
return ret;
}
void bfs()
{
q1.x=startx;
q1.y=starty;
q1.s=mv;
qu.push(q1);
count1[startx][starty]=mv;
while(!qu.empty())
{
q1=qu.front();
qu.pop();
if(q1.s==0)
continue;
for(int k=0;k<=3;k++)
{
q2.x=q1.x+NEXT[k][0];
q2.y=q1.y+NEXT[k][1];
if(q2.x<1||q2.x>m||q2.y<1||q2.y>n)
continue;
if( map1[q2.x][q2.y]=='#'|| map1[q2.x][q2.y]=='Y'|| map1[q2.x][q2.y]=='E')
continue;
q2.s=calulate(q2.x,q2.y,q1.s);
if(q2.s<0)
continue;
if(q2.s>count1[q2.x][q2.y])
{
count1[q2.x][q2.y]=q2.s;
qu.push(q2);
if( map1[q2.x][q2.y]!='P')
ans[q2.x][q2.y]='*';
}
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(count1,-1,sizeof(count1));
memset( map1,0,sizeof( map1));
memset(ans,0,sizeof(ans));
scanf("%d%d%d",&m,&n,&mv);
getchar();
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%c",&map1[i][j]);
ans[i][j]= map1[i][j];
if( map1[i][j]=='Y')
{
startx=i;
starty=j;
}
}
getchar();
}
bfs();
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
printf("%c",ans[i][j]);
printf("\n");
}
printf("\n");
}
return 0;
}
HDU3345广搜 (P,E,T,#)的更多相关文章
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5652(二分+广搜)
题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...
- nyoj 613 免费馅饼 广搜
免费馅饼 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...
- poj 3984:迷宫问题(广搜,入门题)
迷宫问题 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7635 Accepted: 4474 Description ...
- poj 3278:Catch That Cow(简单一维广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45648 Accepted: 14310 ...
- 双向广搜 POJ 3126 Prime Path
POJ 3126 Prime Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16204 Accepted ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- 双向广搜 codevs 3060 抓住那头奶牛
codevs 3060 抓住那头奶牛 USACO 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题目描述 Description 农夫约翰被告知一头逃跑奶牛 ...
- 双向广搜+hash+康托展开 codevs 1225 八数码难题
codevs 1225 八数码难题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Yours和zero在研究A*启 ...
随机推荐
- 在cmd中运行带包名的java程序
例: 在 d 盘中的 zh.java 文件,zh.java文件中有package com.fanShe.....; 则命令是 javac -d . zh.java 要在中间加入 -d . 后面运行的 ...
- XCode7继续用http协议解决办法
昨天被苹果放鸽子也没升级iOS9,今天升级了Xcode7,同时手机升级了iOS9,发现项目报错,查了查才知道是iOS9不支持不安全的http传输协议,让用https协议,这根本就不x现实,,服务端根本 ...
- Vijos p1518 河流 转二叉树左儿子又兄弟
左儿子又兄弟的转发一定要掌握啊,竞赛必用,主要是降低编程复杂度,省时间.个人觉得状压DP也是为了降低编程复杂度. 方程就不说了,程序应该能看得懂,用的记忆化搜索,方便理解. #include<c ...
- sql-char和varchar,nvarchar的区别
数据类型的比较 char表示的是固定长度,最长n个字 varchar表示的是实际长度的数据类型 比如:如果是char类型,当你输入字符小于长度时,后补空格:而是varchar类型时,则表示你输入字符的 ...
- TreeSet和TreeMap的输出
如果加入TreeSet和TreeMap的元素没有实现comprable中的compareTo()方法,那么会报错"treeset cannot be cast to java.lang.Co ...
- Java编程思想学习(十一) 泛型
1.概要 generics enable types (classes and interfaces) to be parameters when defining classes, interfac ...
- poj 3233 矩阵快速幂+YY
题意:给你矩阵A,求S=A+A^1+A^2+...+A^n sol:直接把每一项解出来显然是不行的,也没必要. 我们可以YY一个矩阵: 其中1表示单位矩阵 然后容易得到: 可以看出这个分块矩阵的左下角 ...
- Android模拟器端口被占用问题的解决办法
一.问题描述 今天在Eclipse中运行Android项目时遇到"The connection to adb is down, and a severe error has occured& ...
- MyEclipse------execute()使用方法
execute()方法应该仅在语句能返回多个ResultSet对象,多个更新计数或ResultSet对象与更新计数的组合时使用. testExecute.jsp <%@ page languag ...
- html5新标签转
HTML 5 是一个新的网络标准,目标在于取代现有的 HTML 4.01, XHTML 1.0 and DOM Level 2 HTML 标准.它希望能够减少浏览器对于需要插件的丰富性网络应用服务(p ...