• HDU3345广搜 (P,E,T,#)


    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(" ");
            }
            printf(" ");
        }
        return 0;
    }

     
     
     
     
  • 相关阅读:
    python 利用条件运算符:学习成绩>=90分用A表示,60-89分之间的用B表示,60分以下的用C表示。
    【原创】jmeter解决接口参数MD5加密的问题
    【原创】python+selenium+ddt+unittest实现web功能自动化测试
    【原创】基于RBI的性能测试理念,通过jmeter快速定位接口最大并发用户数
    【原创】基于pyautogui库进行自动化测试
    【原创】面向对象版本地CPU资源占用监控脚本
    【原创】相对完整的一套以Jmeter作为工具的性能测试教程(接口性能测试,数据库性能测试以及服务器端性能监测)
    【部分原创】python实现视频内的face swap(换脸)
    【原创】python基于大数据现实双色球预测
    【原创】python爬虫获取网站数据并存入本地数据库
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/4442613.html
Copyright © 2020-2023  润新知