War Chess (hdu 3345)
http://acm.hdu.edu.cn/showproblem.php?pid=3345
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.
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
...
.E*
.*Y
...***
..**P*
..E*PY
...E**
....T*
.E
EY
..*..
.*P*.
*PYP*
.*P*.
..*..
.E.
EYE
.*.
#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)的更多相关文章
- Aeroplane chess(HDU 4405)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 2道acm编程题(2014):1.编写一个浏览器输入输出(hdu acm1088);2.encoding(hdu1020)
//1088(参考博客:http://blog.csdn.net/libin56842/article/details/8950688)//1.编写一个浏览器输入输出(hdu acm1088)://思 ...
- HDU 5794:A Simple Chess(Lucas + DP)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5794 题意:让一个棋子从(1,1)走到(n,m),要求像马一样走日字型并只能往右下角走.里 ...
- hdu 6114 chess(排列组合)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 5724 Chess(SG函数)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...
- 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 ...
- (多线程dp)Matrix (hdu 2686)
http://acm.hdu.edu.cn/showproblem.php?pid=2686 Problem Description Yifenfei very like play a num ...
- 2012年长春网络赛(hdu命题)
为迎接9月14号hdu命题的长春网络赛 ACM弱校的弱菜,苦逼的在机房(感谢有你)呻吟几声: 1.对于本次网络赛,本校一共6名正式队员,训练靠的是完全的自主学习意识 2.对于网络赛的群殴模式,想竞争现 ...
随机推荐
- socket 进阶
1.验证客户端链接的合法性 如果你想在分布式系统中实现一个简单的客户端链接认证功能,又不像SSL那么复杂,那么利用hmac+加盐的方式来实现 import socket import os impor ...
- Junit4知识梳理
一.junit官网 junit4:http://junit.org/junit4/ junit5:http://junit.org/junit5/ 二.github junit4: https://g ...
- python 找出一篇文章中出现次数最多的10个单词
#!/usr/bin/python #Filename: readlinepy.py import sys,re urldir=r"C:\python27\a.txt" disto ...
- SSH无法连上CentOS7的问题
今天安装完带GNOME的CentOS后发现XShell无法连接上Linux. 原因是sshd服务没有开启.下面是解决办法: 1 ip addr 发现网卡名称为ens33 2 在/etc/sysconf ...
- 后期生成事件命令copy /y
copy /y $(TargetDir)7z.dll ..\..\..\..\webapp\bin copy /y $(TargetDir)7z64.dll ..\..\..\..\webapp\bi ...
- 原生js的dom操作
父节点parentNode 第一个子节点 只会获取到元素节点 firstElementChild ★★★★★ 第一个子节点 (如果有文本节点将会获取到文本节点) firstChild 最 ...
- connect: Address is invalid on local machine or port is not valid on remote
idea 运行正常打成jar包运行提示“connect: Address is invalid on local machine or port is not valid on remote” , 解 ...
- maven clean package 时出现Failed to read artifact descriptor for的问题解决
maven clean package 时出现Failed to read artifact descriptor for的问题 [ERROR] Failed to execute goal on p ...
- windows + php7.1 + redis3.1.4
首先确定PHP版本(MSVC14 x64 NTS) 下载redis扩展 拷贝php ext目录,修改php.ini配置,添加 extension=php_redis.dll 重启apache,确认re ...
- Redis (非关系型数据库) 数据类型 之 String类型
Redis 一个内存数据库,通过 Key-Value 键值对的的方式存储数据.由于 Redis 的数据都存储在内存中,所以访问速度非常快,因此 Redis 大量用于缓存系统,存储热点数据,可以极大的提 ...