栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ACW 4223. 点火游戏 day5

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ACW 4223. 点火游戏 day5

数据范围太小了 问就是暴力 O(T*n^6)

最开始没有清空g啊 非常痛苦!

```

#include
using namespace std;
const int N = 12;
const int mod =11451419;
#define endl 'n'
#define Endl 'n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int n,m,dist[N][N],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char g[N][N];
int bfs(int x,int y,int x1,int y1){
    memset(dist,-1,sizeof dist);
    dist[x][y]=0;
    dist[x1][y1]=0;
    queue>q;
    q.push({x,y});
    q.push({x1,y1});
    while(!q.empty()){
        auto t=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            if(dist[t.first+dx[i]][t.second+dy[i]]==-1&&g[t.first+dx[i]][t.second+dy[i]]=='#'){
                dist[t.first+dx[i]][t.second+dy[i]]=dist[t.first][t.second]+1;
                q.push({t.first+dx[i],t.second+dy[i]});
            }
        }
    }
    int res=-2e9;
    for(int i=0;i
        for(int j=0;j
            if(dist[i][j]==-1&&g[i][j]=='#')return 2e9;
            if(g[i][j]=='#')res=max(res,dist[i][j]);
        }
    }
    return res;
}
signed main(){
    fast
    int t;cin>>t;
    int cnt=0;
    while(t--){
        cnt++;
        cin>>n>>m;
        memset(g,0,sizeof g);
        for(int i=0;i
            for(int j=0;j
                cin>>g[i][j];
            }
        }
        int ans=2e9;
        for(int i=0;i
            for(int j=0;j
                for(int k=i;k
                    int q;
                    if(k==i)q=j;
                    else q=0;
                    for(;q
                        if(g[i][j]!='#')goto out;
                        else if(g[k][q]=='#'){
                            ans=min(ans,bfs(i,j,k,q));
                        }
                    }
                }
                out:1;
            }
        }
        if(ans!=2e9)cout<<"Case "<     }
    return 0^0;
}

```

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/983190.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号