文章

13

粉丝

120

获赞

4

访问

10.4k

头像
石油储藏 题解:
P1564 中国科学院大学2021年机试题
发布于2023年5月5日 20:07
阅读数 552

泛洪算法,从一个点蔓延到整个连通块。

		auto cal = [&](int x,int y) -> void
		{
			queue<pair<int,int>> q;
			q.push({x,y});
			str[x][y] = '*';
			while(q.size())
			{
				auto t = q.front();
				q.pop();
				
				lp(i,0,7)
				{
					int nx = dx[i] + t.fi;
					int ny = dy[i] + t.se;
					if(nx < 1 or ny < 1 or nx > n or ny > m or str[nx][ny] != '@')continue;
					str[nx][ny] = '*';
					q.push({nx,ny});
				}
			}

		};

注意是延伸的方向是八个方向,多加斜方向。

AC代码

#include <bits/stdc++.h>


#define fi first
#define endl '\n'
#define se second
#define pp pop_back
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define all(a) begin(a),end(a)
#define lp(i,j,k) for(int i=int(j);i<=int(k);i++)
#define rlp(i,j,k) for(int i=int(j);i>=int(k);i--)
#define IO std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);

using namespace std;
using ll = long long;
using pii = std::pair<int, int>;
using pll = std:...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发