P1332 血色先锋队

​​​​​​原题链接

没想到这会是福建省历届夏令营的题目,估计也就是第一题的水平吧

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

using namespace std;

typedef pair<int, int> PII;
int n, m, a, b;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 510;
int dist[N][N];
bool st[N][N];
queue<PII> q;

void bfs()
{
    while(q.size())
    {
        auto t = q.front();
        q.pop();
        for (int i = 0; i < 4; i ++ )
        {
            int sx = t.x + dx[i], sy = t.y + dy[i];
            if(sx < 1 || sx > n || sy < 1 || sy > m || st[sx][sy])  continue;
            st[sx][sy] = true;
            dist[sx][sy] = dist[t.x][t.y] + 1;
            q.push({sx, sy});
        }
    }
}

int main()
{
    cin >> n >> m >> a >> b;
    memset(dist, -1, sizeof dist);
    while(a -- )
    {
        int x, y;
        cin >> x >> y;
        dist[x][y] = 0;
        st[x][y] = true;
        q.push({x, y});
    }
    bfs();
    while(b -- )
    {
        int x, y;
        cin >> x >> y;
        cout << dist[x][y] << endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我无法回答关于洛谷P1332C的问题。洛谷是一个在线编程和算法竞赛平台,P1332C可能是一个题目的编号,但我无法提供该题目的详细信息。如果您需要了解有关洛谷P1332C的内容,请访问洛谷网站或使用洛谷相关资源进行查询。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [洛谷 P1332 血色先锋队](https://blog.csdn.net/qq_60854279/article/details/124281589)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [洛谷P1422解答(C++)](https://download.csdn.net/download/qq_42951337/10599493)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [1400集C C++全新企业核心项目攻坚 Ai项目+地震监测+婚恋+游戏+服务引擎 70G容量](https://download.csdn.net/download/qq_41972992/88270318)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值