War Chess (hdu 3345)

时间:2022-12-05 01:26:11

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.
War Chess (hdu 3345)
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&period;编写一个浏览器输入输出(hdu acm1088);2&period;encoding(hdu1020)

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

  3. HDU 5794:A Simple Chess(Lucas &plus; 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&period;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. eclipse控制台中文乱码解决方法

    一.全局设置 1.Window > Preferences 2.General > Workspace > Text file encoding. 3.选择 Other 4.手工输入 ...

  2. 整理一下以前的Html&plus;css3复习笔记

    一.html5新特性  常用语义标签:nav footer header section mark  功能标签 video audio iframe canvas(画布和绘图功能)  input新ty ...

  3. 隐藏StatusBar 非setStatusBarHidden

    UIWindow * window = [[UIApplication sharedApplication].windows lastObject]; 隐藏 [window setWindowLeve ...

  4. php 环境搭建注意事项

    安装php 环境,最后安装集成环境,因为 apache+php 互联不是很容易. 这里主要是两个工具集成工具(wamp ,AppServ),其实这两个集成环境都包括(apache+mysql+php) ...

  5. mybati之&num;与&dollar;的区别

    $是用于sql的拼接: //因为user_name是String类型,所以在sql中加上单引号,需要手动的判断数据类型,value是如果没有指定参数的话,value就是默认参数名称,获取穿的参数就是: ...

  6. Redis:在windows环境安装Redis

    Redis:在windows环境安装Redis 第一步: 下载windows版本的Redis:https://github.com/MSOpenTech/Redis. 第二步: 在命令行执行:D:\r ...

  7. 进阶之初探nodeJS

    一.前言 在"初探nodeJS"随笔中,我们对于node有了一个大致地了解,并在最后也通过一个示例,了解了如何快速地开启一个简单的服务器. 今儿,再次看了该篇随笔,发现该随笔理论知 ...

  8. restful 跨域

    同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能. 就浏览器而言的, http://127.0.0.1:8000  协议 域名 端口 跨域 问题// 简单 ...

  9. JavascriptDom编程艺术&lpar;笔记&rpar;

    如果想快速学习dom的话,建议去菜鸟教程,比较浅显易懂,实战性较强.我是看纸质的书,主要是花钱,心疼,所以看完,容易记住. 1.重点: .变量 -.var修饰 -.赋值,用=号,例如ver age = ...

  10. Eclipse使用maven命令安装第三方jar包

    使用原因: 使用maven时,有些第三方jar包是不能从maven远程仓库中下载得到,因此导致在pom.xml中添加jar包依赖时会怎么添加都会报错(Missing artifact ojdbc:oj ...