AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
    • 吐槽
  • App
  • 登录/注册

AcWing 3200. 无线网络

作者: 作者的头像   Unkillable ,  2023-05-26 00:06:11 ,  所有人可见 ,  阅读 5


0


#include<bits/stdc++.h>

using namespace std;

#define x first
#define y second

using LL = long long;

using PII = pair<int, int>;

const int N = 250, M = N * N;

int n, m, k, r;
int h[N], e[M], ne[M], idx;
PII p[N];
int dist[N][N];

bool check(PII a, PII b)
{
    LL dx = a.x - b.x;
    LL dy = a.y - b.y;
    return dx * dx + dy * dy <= (LL)r * r;
}

void add(int a, int b)
{
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}

int bfs()
{
    queue<PII> q;
    q.push({1, 0});
    memset(dist, 0x3f, sizeof dist);
    dist[1][0] = 0;

    while(q.size())
    {
        auto t = q.front();
        q.pop();

        for(int i = h[t.x]; i != -1; i = ne[i])
        {
            int x = e[i], y = t.y;
            if(x > n) y++;
            if(y <= k)
            {
                if(dist[x][y] > dist[t.x][t.y] + 1)
                {
                    dist[x][y] = dist[t.x][t.y] + 1;
                    q.push({x, y});
                }
            }
        }
    }

    int res = 1e8;
    for(int i = 0; i <= k; i++)
        res = min(res, dist[2][i]);

    return res - 1;
}

int main()
{
    cin >> n >> m >> k >> r;
    memset(h, -1, sizeof h);
    for(int i = 1; i <= n; i++)
        cin >> p[i].x >> p[i].y;

    for(int i = n + 1; i <= n + m; i++)
        cin >> p[i].x >> p[i].y;

    for(int i = 1; i <= n + m; i++)
        for(int j = i + 1; j <= n + m; j++)
        if(check(p[i], p[j]))
            add(i, j), add(j, i);

    cout << bfs();

    return 0;
}

0 评论

你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息