zoukankan      html  css  js  c++  java
  • HDU 4478

    这道题纠结了很久,一开始想一层一层地算,但是各种空间超出,然后百度了人家的解法,还是不错的想法,就是说第n 步走到这里,第n+2步也会走到这里。

    值得注意的是它不会走当前所在的可能的位置。   看一个简单的图片,或许会一目了然.

    #include<iostream>
    #include<string>
    #include<string.h>
    #include<stdio.h>
    #include<queue>
    #include<math.h>
    using namespace std;
    int n,x,y,T;
    char mapp[110][110];
    int vis[110][110][2];
    struct node{
        int x;int y;
        int step;
    };
    queue<node> q;
    int dir[8][2]={{1,0},{1,1},{0,1},{-1,0},{-1,1},{-1,-1},{0,-1},{1,-1}};
    void bfs(){
        node temp,next;
        int f,h;
        while(!q.empty()){
            temp=q.front();
            q.pop();
            if(temp.step>=T) break;
            for(int i=0;i<8;i++){
                f=temp.x+dir[i][0];
                h=temp.y+dir[i][1];
                if(f>=1&&f<=n&&h>=1&&h<=n&&mapp[f][h]!='#'){
                    next.x=f;
                    next.y=h;
                    next.step=temp.step+1;
                    if(!vis[f][h][next.step%2]){
                    q.push(next);
                    vis[f][h][next.step%2]=1;
                    }
                }
            }
        }
    
        int yy=T%2,ans=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(vis[i][j][yy])
                {
                    ans++;
                }
            }
        }
    
        cout<<max(ans,1)<<endl;
    
    
    }
    int main(){
       int t;
       cin>>t;
       while(t--){
        cin>>n>>T>>x>>y;
        memset(mapp,0,sizeof(mapp));
        memset(vis,0,sizeof(vis));
        while(!q.empty()) q.pop();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++)
                cin>>mapp[i][j];
        }
        node tt;
        tt.x=x;tt.y=y;tt.step=0;
        vis[x][y][0]=1;
        q.push(tt);
    
       bfs();
    
       }
    
        return 0;
    }
  • 相关阅读:
    2020/1/27 代码审计学习-宽字节注入与二次注入
    2020/1/27代码审计学习之SQL注入漏洞
    2020/1/27代码审计学习之审计涉及的超全局变量
    2019总结与最近
    鸽一天
    [极客大挑战 2019]Knife
    [LuoguP1438]无聊的数列(差分+线段树/树状数组)
    [BJWC2018]最长上升子序列
    笙上月
    笔下梅
  • 原文地址:https://www.cnblogs.com/wintersong/p/5237390.html
Copyright © 2011-2022 走看看