#include<iostream>
#include<vector>
#include<deque>
#include<cstring>
#include<algorithm>
using namespace std;
struct node {
long long int x, y;
int len1[105], len2[105];
vector<int> ner;
node() { x = 0; y = 0; len1[0] = len2[0] = 9999; }
};
bool cmp(node a, node b, long long int r) {
return (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) <= r*r;
}
node all[205];
long long int n, m, k, r;
int vis[205];
void update(int index,int t) {
for (int i = 0; i < all[index].ner.size(); ++i) {
if (all[index].len1[t]+1<min(all[all[index].ner[i]].len1[t-1], all[all[index].ner[i]].len1[t])) {
all[all[index].ner[i]].len1[t] = all[index].len1[t] + 1;
update(all[index].ner[i],t);
}
else {
all[all[index].ner[i]].len1[t] = min(all[all[index].ner[i]].len1[t - 1], all[all[index].ner[i]].len1[t]);
}
if (all[index].len2[t] + 1<min(all[all[index].ner[i]].len2[t - 1], all[all[index].ner[i]].len2[t])) {
all[all[index].ner[i]].len2[t] = all[index].len2[t] + 1;
update(all[index].ner[i], t);
}
else {
all[all[index].ner[i]].len2[t] = min(all[all[index].ner[i]].len2[t - 1], all[all[index].ner[i]].len2[t]);
}
}
}
int main() {
cin >> n >> m >> k >> r;
for (int i = 1; i <= n+m; ++i) {
cin >> all[i].x >> all[i].y;
}
for (int i = 1; i <= n + m; ++i) {
for (int j = 1; j <= n + m; ++j)
if (i!=j &&cmp(all[i], all[j], r)) all[i].ner.push_back(j);
}
all[1].len1[0] = 0;
deque<int> tmp;
tmp.push_back(1);
vis[1] = 1;
while (!tmp.empty()) {
int e = tmp.front();
tmp.pop_front();
for (int i = 0; i < all[e].ner.size(); ++i) {
if (!vis[all[e].ner[i]] && all[e].ner[i] <= n) {
vis[all[e].ner[i]] = 1;
all[all[e].ner[i]].len1[0] = all[e].len1[0] + 1;
tmp.push_back(all[e].ner[i]);
}
}
}
all[2].len2[0] = 0;
memset(vis, 0, sizeof(int)*(n+1));
vis[2] = 1;
tmp.push_back(2);
while (!tmp.empty()) {
int e = tmp.front();
tmp.pop_front();
for (int i = 0; i < all[e].ner.size(); ++i) {
if (!vis[all[e].ner[i]] && all[e].ner[i] <= n) {
vis[all[e].ner[i]] = 1;
all[all[e].ner[i]].len2[0] = all[e].len2[0] + 1;
tmp.push_back(all[e].ner[i]);
}
}
}
for(int t=1;t<=k;++t){
for (int i = n+1; i <= m + n; ++i) {
all[i].len1[t] = all[i].len2[t] = 9999;
for (int j = 0; j < all[i].ner.size(); ++j) {
all[i].len1[t] = min(all[i].len1[t],min(all[i].len1[t-1], all[all[i].ner[j]].len1[t-1] + 1));
all[i].len2[t] = min(all[i].len2[t],min(all[i].len2[t-1], all[all[i].ner[j]].len2[t-1] + 1));
}
}
for (int i = 1; i <= m + n; ++i) {
if (i <= n) { all[i].len1[t] = all[i].len1[t - 1]; all[i].len2[t] = all[i].len2[t - 1]; }
else update(i,t);
}
}
cout << all[1].len1[k] + all[1].len2[k] - 1 << endl;
}
ccf 201403-4 无线网络
最新推荐文章于 2023-02-19 20:18:04 发布