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.对于网络赛的群殴模式,想竞争现 ...
随机推荐
- 前端基础之JavaScript day51
前端基础之JavaScript JavaScript概述 JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中) ...
- laravel中类似于thinkPHP中trace功能
答案来自https://segmentfault.com/q/1010000007716945 一楼: 到 https://packagist.org 上搜索你想要的关键词,比如查debugbar 列 ...
- ---转载---phython资料
整理汇总,内容包括长期必备.入门教程.练手项目.学习视频. 一.长期必备. 1. StackOverflow,是疑难解答.bug排除必备网站,任何编程问题请第一时间到此网站查找. https://st ...
- c#networkcomms protobuf-net 文件加载出现问题
服务器端里添加客户管理添加了些功能, 客户端私活连不上了,老程序没问题, 在服务器端程序里边也接受不到事件,客户端就提示链接中断了, 在客户端里边查了 链接中断是客户端上做的,当传回的包为0 事,程序 ...
- JAVA动手动脑及课后作业
1.查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? 运行结果 true true false 原因 1)在Java中,内容相同的字串常量(“Hello”)只保存一份以节约内存,所以s0, ...
- 关于sublime Text 3安装sublimecodeIntel插件配置方法
打开preferences-package settings-sublimecodeIntel-settings users 添加 { "JavaScript": { " ...
- 最大子序列(java版)
package com.algorithm.test; /** * 最大子序列 * @author LiFen * */ public class LargestSubsequence { publi ...
- 请简要介绍Sping MVC、IoC和AOP
Sping MVC是在Spring框架上发展起来的框架,它提供了构建Web应用程序的全功能MVC模块,使用了Spring可插入的MVC架构,可以自由的选择各个模块所使用的架构,非常灵活.Spring ...
- 进化树(phylogenetic trees)
构建进化树的工具有: muscle mega 进化树的可视化: 本地可视化软件 Figtree (网址:http://tree.bio.ed.ac.uk/software/figtree/) 该软件是 ...
- python文件读取操作、序列化
1.对文件进行读写操作时,先建立文件句柄 f = open("test.txt","r",encoding="UTF-8") 其中,r为文件 ...