http://acm.hdu.edu.cn/showproblem.php?pid=3345

Problem Description
War chess is hh's favorite game:
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.
 
Input
The first line of the inputs is T, which stands for the number of test cases you need to solve.
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.
 
Output
Output the N*M map, using '*'s to replace all the grids 'Y' can arrive (except the 'Y' grid itself). Output a blank line after each case.
 
Sample Input
5
3 3 100
...
.E.
..Y

5 6 4
......
....PR
..E.PY
...ETT
....TT

2 2 100
.E
EY

5 5 2
.....
..P..
.PYP.
..P..
.....

3 3 1
.E.
EYE
...

 
Sample Output
...
.E*
.*Y

...***
..**P*
..E*PY
...E**
....T*

.E
EY

..*..
.*P*.
*PYP*
.*P*.
..*..

.E.
EYE
.*.

 
Author
shǎ崽
 
Source
 
主要的是规则:Y  是它的起始点
             .  需要让 cost 减1
             T   需要让 cost 减2
             R  需要让  cost 减3
             #  不能走
             P   需要让 cost 减1
             E  不能走, 但走到它周围的 cost 都要变为 0
             除了 P 以外能到达的点, 走过后都要变为 * 
 
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<cmath>
#include<vector>
using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f;
const int N = ;
#define met(a, b) memset (a, b, sizeof(a)) struct node
{
int x, y, cost;
bool operator < (const node &a)const
{
return cost<a.cost;
}
}Y; int dir[][]={{-,},{,},{,-},{,}};
int n, m, vis[N][N];
char s[N][N]; int Judge(int x, int y)
{
if(x>= && x<n && y>= && y<m)
return ;
return ;
} int Judge1(int x, int y)
{
int nx, ny, i;
for(i=; i<; i++)
{
nx = x + dir[i][];
ny = y + dir[i][];
if(Judge(nx, ny) && s[nx][ny]=='E')
return ;
}
return ;
} void BFS()
{
node p, q; met(vis, );
vis[Y.x][Y.y] = ; priority_queue<node>Q;
Q.push(Y); while(Q.size())
{
p = Q.top(), Q.pop();
for(int i=; i<; i++)
{
q.x = p.x + dir[i][];
q.y = p.y + dir[i][];
if(Judge(q.x, q.y) && !vis[q.x][q.y] && s[q.x][q.y]!='#' && s[q.x][q.y]!='E')
{
if(s[q.x][q.y]=='.' || s[q.x][q.y]=='P')
q.cost = p.cost - ;
if(s[q.x][q.y]=='T')
q.cost = p.cost - ;
if(s[q.x][q.y]=='R')
q.cost = p.cost - ;
if(Judge1(q.x, q.y))
{
vis[q.x][q.y] = ;
Q.push(q);
}
if(s[q.x][q.y]!='P'&& q.cost>=)
s[q.x][q.y]='*' ;
}
}
}
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int i, j, cost; scanf("%d%d%d", &n, &m, &cost); for(i=; i<n; i++)
{
scanf("%s", s[i]);
for(j=; j<m; j++)
{
if(s[i][j]=='Y')
Y.x = i, Y.y = j, Y.cost = cost;
}
} BFS(); for(i=; i<n; i++)
printf("%s\n", s[i]);
printf("\n");
}
return ;
}
 

War Chess (hdu 3345)的更多相关文章

  1. Aeroplane chess(HDU 4405)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)

    //1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...

  3. HDU 5794:A Simple Chess(Lucas + DP)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5794 题意:让一个棋子从(1,1)走到(n,m),要求像马一样走日字型并只能往右下角走.里 ...

  4. hdu 6114 chess(排列组合)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. HDU 5724 Chess(SG函数)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...

  7. 2013 多校联合 F Magic Ball Game (hdu 4605)

    http://acm.hdu.edu.cn/showproblem.php?pid=4605 Magic Ball Game Time Limit: 10000/5000 MS (Java/Other ...

  8. (多线程dp)Matrix (hdu 2686)

    http://acm.hdu.edu.cn/showproblem.php?pid=2686     Problem Description Yifenfei very like play a num ...

  9. 2012年长春网络赛(hdu命题)

    为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...

随机推荐

  1. rem初始化

    使用css实现rem适配,头部引入即可 adaptive.js !function(e, t) { function i() { o = , e.devicePixelRatioValue = o, ...

  2. stl之容器、迭代器、算法几者之间的关系

    转自:https://blog.csdn.net/bobodem/article/details/49386131 stl包括容器.迭代器和算法: 容器 用于管理一些相关的数据类型.每种容器都有它的优 ...

  3. Andriod——手机尺寸相关的概念 +尺寸单位+关于颜色

    手机的尺寸: 屏幕对角线的长度,单位为英寸(2.54cm) 手机的分辨率: 屏幕能显示的像素的数量, 一般用在长方向上数量*宽方向上数量来表达 手机的像素密度: pixels per inch,也称P ...

  4. Oracle数据库mybatis 插入空值时报错(with JdbcType OTHER)

    参考文档: 1.https://blog.csdn.net/fishernemo/article/details/27649233 2.http://helgaxu.iteye.com/blog/21 ...

  5. Delphi、Lazarus保留字、关键字详解

    Delphi.Lazarus保留字.关键字详解 来自橙子,万一的博客以及其他地方 保留字:变量等标识符可以再使用: 关键字:有特定含义,不能再次重新定义: 修饰字:类似保留字的功能,也就是说可以重用 ...

  6. html里<div> <br /> <p>三者区别

    一.语法不同   -   TOP div和p是成对组合闭合标签:<br />是单一的闭合标签. 以<div>开始,</div>结束:以<p>开始,< ...

  7. fastcgi vc6.0demo

    #include <WinSock2.h> #include <stdio.h> #pragma comment(lib, "ws2_32.lib") ty ...

  8. 内存溢出和内存泄漏的区别(ZZ)

      内存溢出 out of memory,是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory:比如申请了一个integer,但给它存了long才能存下的数,那就是内存溢出 ...

  9. 局外者看 -- 美团 vs 滴滴

    1. 美团 美团外面 美团打车 美团云服务 2. 滴滴 滴滴打车 滴滴外面 滴滴云服务 这是一场企业级别的战争,而且是本土战争,时间开始于何时,不知道,现在写这个博客的时间是2018年3月21日下午. ...

  10. zk实现分布式锁

    public interface lock { void getLock(); void unLock(); } public abstract class ZkAbstractLock implem ...