文章

160

粉丝

0

获赞

691

访问

26.4k

头像
生化武器 题解:
P1126
发布于2026年3月8日 16:45
阅读数 112

#include<iostream>
#include<cstring>
#include<queue>
#define x first
#define y second

using namespace std;

const int N=32;

int n,m,t,cnt;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
char g[N][N];

void bfs(int x0,int y0)
{
    queue<pair<int,int>> q;
    q.push({x0,y0});
    g[x0][y0]='#';
    while(t--)
    {
        queue<pair<int,int>> q_=q;
        while(!q_.empty())
        {
            auto u=q_.front();
            q_.pop();
            int a=u.x,b=u.y;
            for(int i=0;i<4;i++)
            {
                int x=a+dx[i],y=b+dy[i];
                if(x<0||x>=n||y<0||y>=strlen(g[x]))
                continue;
                if(g[x][y]=='.')
                {
                    g[x][y]='#';
                    cnt--;
                    q.push({x,y});
                }
            }
        }
    }
}

int main()
{
    while(cin>>n>>m>>t)
    {
   ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发