AcWing 3200. 无线网络
原题链接
中等
作者:
二十六
,
2025-03-28 01:34:32
·辽宁
,
所有人可见
,
阅读 1
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int N = 210;
typedef long long ll;
typedef pair<int, int> PII;
vector<int> qs[N];
PII vinfoS[N];
ll n, m, k, r;
int d[N][N];
bool check(int i, int j) {
ll dx = vinfoS[i].first - vinfoS[j].first;
ll dy = vinfoS[i].second - vinfoS[j].second;
if (dx * dx + dy * dy <= r * r) {
return true;
}
else {
return false;
}
}
int main() {
cin >> n >> m >> k >> r;
for (int i = 0; i < n + m; i ++) {
cin >> vinfoS[i].first >> vinfoS[i].second;
}
for (int i = 1; i < n + m; i++) {
for (int j = 0; j < i; j++) {
if (check(i, j)) {
qs[i].push_back(j);
qs[j].push_back(i);
}
}
}
queue<int> q;
q.push(0);
memset(d, 0x3f, sizeof d);
d[0][0] = 0;
while (q.size()) {
int out = q.front();
q.pop();
for (auto x : qs[out]) {
if (x >= n) {
for (int j = 0; j < k; j ++) {
if (d[x][j + 1] > d[out][j] + 1) {
d[x][j + 1] = d[out][j] + 1;
q.push(x);
}
}
}
else {
for (int j = 0; j <= k; j ++) {
if (d[x][j] > d[out][j] + 1) {
d[x][j] = d[out][j] + 1;
q.push(x);
}
}
}
}
}
int ans = m + n;
for (int i = 0; i <= k; i++) {
if (ans > d[1][i]) {
ans = d[1][i];
}
}
cout << ans - 1 << endl;
return 0;
}