War Chess

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5   Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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
.*. 自己写的spfa代码:
注意输出的每行后面都有一个空行,我就错了presentation error。。。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; struct node
{
int x,y;
node(int a,int b){x=a; y=b;}
};
int dr[][]={{,},{,},{-,},{,-}};
int n,m,mv,t,sx,sy;
int dis[][];
bool vis[][];
char mp[][]; bool work(int x,int y)
{
if(mp[x][y]=='Y') return ;
for(int i=;i<;i++)
{
int xx=x+dr[i][];
int yy=y+dr[i][];
if(xx< || xx>=n || yy< || yy>=m) continue;
if (mp[xx][yy]=='E') return ;
}
return ;
}
void spfa()
{
queue<node> Q;
memset(dis,-,sizeof(dis));
memset(vis,,sizeof(vis));
Q.push(node(sx,sy));
dis[sx][sy]=mv;
vis[sx][sy]=;
while(!Q.empty())
{
node p=Q.front();
vis[p.x][p.y]=;
Q.pop();
if (work(p.x,p.y)) dis[p.x][p.y]=;
if (dis[p.x][p.y]>)
for(int i=;i<;i++)
{
int xx=p.x+dr[i][];
int yy=p.y+dr[i][];
char ch=mp[xx][yy];
if(xx< || xx>=n || yy< || yy>=m) continue;
if(ch=='#') continue;
if(ch=='.'|| ch=='T' || ch=='R')
{
int k;
if (ch=='.') k=; else
if (ch=='T') k=; else
if (ch=='R') k=;
if (dis[xx][yy]>=dis[p.x][p.y]-k) continue;
dis[xx][yy]=dis[p.x][p.y]-k;
if(!vis[xx][yy])
{
Q.push(node(xx,yy));
vis[xx][yy]=;
}
}
if(ch=='P' && dis[p.x][p.y]>)
{
if (dis[xx][yy]>=dis[p.x][p.y]-) continue;
dis[xx][yy]=dis[p.x][p.y]-;
if(!vis[xx][yy])
{
Q.push(node(xx,yy));
vis[xx][yy]=;
}
}
}
}
}
int main()
{
scanf("%d",&t);
for(;t>;t--)
{
scanf("%d%d%d",&n,&m,&mv);
for(int i=;i<n;i++)
{
scanf("%s",&mp[i]);
for(int j=;j<m;j++)
if (mp[i][j]=='Y') sx=i,sy=j;
} spfa();
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if (dis[i][j]<) printf("%c",mp[i][j]);
else
{
if (mp[i][j]=='E' || mp[i][j]=='P' || mp[i][j]=='Y') printf("%c",mp[i][j]);
else printf("*");
}
}
printf("\n");
}
printf("\n");
}
return ;
}

转自:http://www.bkjia.com/cjjc/857812.html
/*
bfs+优先队列,刚开始没有优化,果断超时,第二次竟然因为优先级符号TLE!!(该记得的东西真得记牢) 使用mark数组记录该点MV值大小,初始化为零,搜索时只有当从某个点到达当前点使MV变大时才把该点值更新;入队时判断该点MV值是否大于零,大于则入队。 具体看代码:
*/
#include"stdio.h"
#include"string.h"
#include"queue"
#include"vector"
#include"algorithm"
using namespace std;
#define N 105
#define max(a,b) (a>b?a:b)
int mark[N][N],n,m,v;
int dir[][]={,,,-,-,,,};
char str[N][N];
struct node
{
int x,y,d;
friend bool operator<(node a,node b)
{
return a.d=&&x=&&yq;
node cur,next;
cur.x=x;cur.y=y;cur.d=v;
q.push(cur);
memset(mark,-,sizeof(mark));
mark[x][y]=v;
while(!q.empty())
{
cur=q.top();
q.pop();
for(i=;i<;i++)
{
next.x=x=dir[i][]+cur.x;
next.y=y=dir[i][]+cur.y;
if(judge(x,y))
{
if(str[x][y]=='.'||str[x][y]=='P')
t=cur.d-;
else if(str[x][y]=='T')
t=cur.d-;
else if(str[x][y]=='R')
t=cur.d-;
else
t=-;
if(ok(x,y)&&t>)
t=; //战斗力减为0
if(t>&&t>mark[x][y])
{
next.d=t;
q.push(next);
}
mark[x][y]=max(mark[x][y],t);
}
}
}
}
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&v);
for(i=;i=)
{
if(str[i][j]!='P'&&str[i][j]!='Y')
printf("*");
else
printf("%c",str[i][j]);
}
else
printf("%c",str[i][j]);
}
puts("");
}
puts("");
}
return ;
}

hdu 3345 War Chess的更多相关文章

  1. HDU - 3345 War Chess 广搜+优先队列

    War chess is hh's favorite game: In this game, there is an N * M battle map, and every player has hi ...

  2. 【HDOJ】3345 War Chess

    简单BFS.注意最后一组数据,每个初始点不考虑周围是否有敌人. /* 3345 */ #include <iostream> #include <cstdio> #includ ...

  3. War Chess (hdu 3345)

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 Problem Description War chess is hh's favorite game:I ...

  4. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  5. War Chess bfs+优先队列

    War chess is hh's favorite game: In this game, there is an N * M battle map, and every player has hi ...

  6. HDU 5724:Chess(博弈 + 状压)

    http://acm.hdu.edu.cn/showproblem.php?pid=5724 Chess Problem Description   Alice and Bob are playing ...

  7. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  8. HDU 3345

    http://acm.hdu.edu.cn/showproblem.php?pid=3345 最近重写usaco压力好大,每天写的都想吐.. 水一道bfs 注意的是开始旁边有敌人可以随便走,但是一旦开 ...

  9. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

随机推荐

  1. Digital Ocean VS. Linode对比评测

    美国攻城师Zach Schneider是linode vps资深用户,他最近却转向了Digital Ocean,原因是什么呢?来看这篇digitalocean linode对比评测的文章: 用了两年的 ...

  2. 【笔记】Loadrunner添加OS类型为Windows的服务器(Win7)

    最近在学习Loadrunner,看到“监控Windows资源”,决定小试一把,由于没有找到合适的镜像,暂时没有搞好Windows的虚拟机,so 先用自己小试牛刀了只有,不过这样子好像难度锐减也~只要小 ...

  3. ubuntu下打开chm文件

    CHM文件格式是微软1998年推出的基于HTML文件特性的帮助文件系统,以替代早先的WinHelp帮助系统,它在Windows 98中把CHM类型文件称作“已编译的HTML帮助文件”. chm文件因为 ...

  4. FireFox站点标识按钮

    Firefox 的站点标识按钮可以为您提供有关您访问的网站的详细信息.通过站点标识按钮,您可以了解到站点的加密信息.验证信息.网站所有者和网站验证者.这有助于避免恶意网站获得您的重要信息. 站点标识按 ...

  5. 6.编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print 类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的 立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来 测试类Print。

    Print类: package com.bao; public class Print { int g,s,b; void outPut() { for(int i=100;i<1000;i++ ...

  6. html 图片上传预览

    Html5 upload img 2012年12月27日 20:36 <!DOCTYPE HTML> <html> <head> <meta http-equ ...

  7. CVE-2014-4115漏洞分析(2014.11)

    CVE-2014-4115漏洞分析 一.简介 该漏洞是由于Windows的Fastfat.sys组件在处理FAT32格式的硬盘分区存在问题.攻击者利用成功可导致权限提升. 影响的系统包括: Windo ...

  8. android 按钮Button单击背景切换

    res/drawable/btn_selected.xml <?xml version="1.0" encoding="utf-8"?> <s ...

  9. ios设置textField只能输入数字用于电话号码

    首先在.xib中将UITextField的Keyboard设置为Number Pad,但是使用时键盘会切回别的键盘无法对内容进行校验.通过神奇的百度我知道了通过以下方法可以解决这样的问题: 首先让.x ...

  10. hdu_5768_Lucky7(中国剩余定理+容斥)

    题目链接:hdu_5768_Lucky7 题意: 给你一个区间,问你这个区间内是7的倍数,并且满足%a[i]不等于w[i]的数的个数 乍一看以为是数位DP,仔细看看条件,发现要用中国剩余定理,然后容斥 ...