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
 
 
 

#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
char  map1[105][105],ans[105][105];
int m,n,mv;
 int startx,starty;
int count1[105][105];
int NEXT[4][2]={1,0,0,-1,-1,0,0,1};
struct node
{
    int x;
    int y;
    int s;
}q1,q2;
 queue<node>qu;
int calulate(int x1,int y1,int v)
{
    int tx,ty,ret;
    if( map1[x1][y1]=='T')
        ret=v-2;
    else  if( map1[x1][y1]=='R')
        ret=v-3;
    else
        ret=v-1;
    for(int i=0;i<=3;i++)
    {
        tx=x1+NEXT[i][0];
        ty=y1+NEXT[i][1];
        if(tx<1||tx>m||ty<1||ty>n)
           continue;
        if( map1[tx][ty]=='E')
            {
                if(ret>0)
                return 0;
                else
                    return ret;
            }
    }
    return ret;
}

void bfs()
{

q1.x=startx;
    q1.y=starty;
    q1.s=mv;
    qu.push(q1);
    count1[startx][starty]=mv;
    while(!qu.empty())
    {
        q1=qu.front();
        qu.pop();
        if(q1.s==0)
            continue;
        for(int k=0;k<=3;k++)
        {
            q2.x=q1.x+NEXT[k][0];
            q2.y=q1.y+NEXT[k][1];
            if(q2.x<1||q2.x>m||q2.y<1||q2.y>n)
            continue;
           if( map1[q2.x][q2.y]=='#'|| map1[q2.x][q2.y]=='Y'|| map1[q2.x][q2.y]=='E')
           continue;
           q2.s=calulate(q2.x,q2.y,q1.s);
           if(q2.s<0)
            continue;
           if(q2.s>count1[q2.x][q2.y])
           {
               count1[q2.x][q2.y]=q2.s;
               qu.push(q2);
               if( map1[q2.x][q2.y]!='P')
                ans[q2.x][q2.y]='*';
           }
        }
    }
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(count1,-1,sizeof(count1));
        memset( map1,0,sizeof( map1));
        memset(ans,0,sizeof(ans));

scanf("%d%d%d",&m,&n,&mv);
        getchar();

for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
                {
                    scanf("%c",&map1[i][j]);
                    ans[i][j]= map1[i][j];
                    if( map1[i][j]=='Y')
                    {
                        startx=i;
                        starty=j;
                    }

}
                getchar();
        }

bfs();
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
                printf("%c",ans[i][j]);
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

 
 
 
 

HDU3345广搜 (P,E,T,#)的更多相关文章

  1. HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?

    这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others)  ...

  2. HDU 5652(二分+广搜)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...

  3. nyoj 613 免费馅饼 广搜

    免费馅饼 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...

  4. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  5. poj 3278:Catch That Cow(简单一维广搜)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 45648   Accepted: 14310 ...

  6. 双向广搜 POJ 3126 Prime Path

      POJ 3126  Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16204   Accepted ...

  7. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  8. 双向广搜 codevs 3060 抓住那头奶牛

    codevs 3060 抓住那头奶牛 USACO  时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold   题目描述 Description 农夫约翰被告知一头逃跑奶牛 ...

  9. 双向广搜+hash+康托展开 codevs 1225 八数码难题

    codevs 1225 八数码难题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description Yours和zero在研究A*启 ...

随机推荐

  1. Source Tree for MAC1.6

    Atlassian ID has become the new Atlassian Account. Read more about it here. After some great communi ...

  2. 读代码之htmlParser

    在以前使用HtmlParser时,并未考虑过遇到org.htmlparser.tags之外的Tag怎么处理.直到碰到这样的一个标签,如果不加处理,HtmlParser无法对其进行处理.查阅自定义标签之 ...

  3. 如何在Oracle中导入dmp文件

    Oracle数据导入导出imp/exp就相当于oracle数据还原与备份.exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中. 利 ...

  4. ajax中的application/x-www-form-urlencoded中的使用

    ajax中的application/x-www-form-urlencoded中的使用一,HTTP上传的基本知识 在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定 ...

  5. The first gui program by Qt

    #include<QApplication> #include<QPushButton> int main(int argc, char **argv) {     QAppl ...

  6. nginx 下 location 配置解释

    当我们在使用负载均衡和反向代理的时候 我们会考到虚拟主机下面有着个配置 现在我们看一下反向代理的location 下面的配置实例: server { listen 80 ;    监听的端口号 ser ...

  7. Centos下apache启动时httpd: apr_sockaddr_info_get() failed for 报错

    今天安装Apache httpd web服务器时,从官方网站上http://www.apache.org/dyn/closer.cgi下载httpd,然后在centos下解压,安装过程分为三部分: ( ...

  8. TS

    //html文件 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  9. Spring-涉及到的设计模式汇总

    1. 简单工厂 又叫做静态工厂方法(StaticFactory Method)模式,但不属于23种GOF设计模式之一. 简单工厂模式的实质是由一个工厂类根据传入的参数,动态决定应该创建哪一个产品类. ...

  10. 【转】mac os x系统上Android开发环境的搭建

    由于Google官方已经不提供Adt-Bundle下载了,主推AndroidStudio.可以从这个链接下载http://www.androiddevtools.cn.上面不光有adt-bundle, ...