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. Python 列表推导实例

    #!/usr/bin/python # -*- coding: utf-8 -*- with open('e:/123.txt') as fp:row = fp.readlines() #打开并读取所 ...

  2. 5B - 一只小蜜蜂...

    有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示.  Input 输入数据的第一行是一个整数N,表示测试实例的个数,然 ...

  3. [转载] Linux中的搜索文件命令

    搜索文件用处很大,我们往往需要知道一个文件存放在什么地方,我们又知道Linux是命令强大的一个系统,所以也有好多非常优秀的搜索命令.通常find不常用,因为速度慢,耗费硬盘空间.通常我们先使用wher ...

  4. BZOJ2730或洛谷3225 [HNOI2012]矿场搭建

    BZOJ原题链接 洛谷原题链接 显然在一个点双连通分量里,无论是哪一个挖煤点倒塌,其余挖煤点就可以互相到达,而对于一个点双连通分量来说,与外界的联系全看割点,所以我们先用\(tarjan\)求出点双连 ...

  5. vim自动添加tags、cscope

    每次打开一个工程都需要重新添加tags.cscope,很不方便,网上找了一下. 将其添加到 ~/.vimrc 中之后,打开 vim 就会自动搜索当前路径下的tags.cscope添加进去. 自动添加 ...

  6. 拼图类APP原型模板分享——简拼

    简拼是一款记录美好.抒写情怀的拼图APP,模板设计风格简约文艺,种类齐全. 此原型模板所用到的组件有标签组.水平分隔线.圆形工具.交互动作有结合标签组实现页面跳转,选择组件触发按钮状态变化等. 此原型 ...

  7. wepy中页面的跳转

    1.在pages中创建好页面之后,需要在app.wpy中的config中配置好页面路由:2.如果跳转的按钮在page页面中 this.$navigate({url:"content" ...

  8. .net获取本地ip地址

    整理代码,.net获取本地ip地址,代码如下: string name = Dns.GetHostName(); IPHostEntry IpEntry = Dns.GetHostEntry(name ...

  9. day08作业---函数

    '''2.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者.'''#学会了 原来 range(len(iter)) 是 从零到len-1 的数的组合 建新放在 ...

  10. 模块and包

    一.模块 1.import 加载的模块四个通用类别 1.使用python编写的py文件 2.已被编译为共享库或者DLL或者C\C++的扩展 3.包好一组模块的包 4.使用c编写并连接到python解释 ...