CCF201403-4

CCF201403-4

#include<iostream>
#include<queue>
#include<vector>
using namespace std;

typedef struct route{
	long long  x,y;
	int step;
	int count;
}route;
bool below(long long x1,long long y1,long long x2,long long y2,long long r){
	long long x = (x1-x2)*(x1-x2);
	long long y = (y1-y2)*(y1-y2);
	return (x+y <= r*r);
}
int BFS(int n,int m,int k,long long r){
	vector<vector<long long> > array(n+m,vector<long long>(2,0));
	for(int i=0;i<n+m;i++){
		cin>>array[i][0]>>array[i][1];
	}	
	vector<bool> visit(n+m,false);
	queue<route> q;
	route first;
	first.x = array[0][0];
	first.y = array[0][1];
	first.step = 0;
	first.count = 0;
	q.push(first);
	visit[0] = true;
	long long ex = array[1][0];
	long long ey = array[1][1];
	while(!q.empty()){
		route front = q.front();
		long long x = front.x;
		long long y = front.y;
		q.pop();
		
		if(x==ex&&y==ey){
			return front.step-1;
		}
		for(int i=0;i<n+m;i++){
			if(!visit[i]&&below(x,y,array[i][0],array[i][1],r)){
				visit[i] = true;
				route tmp;
				tmp.x = array[i][0];
				tmp.y = array[i][1];
				if(i>=n){
					tmp.count = front.count + 1;
				}
				else{
					tmp.count = front.count ;
				}
				tmp.step = front.step+1;
				if(tmp.count<=k)
					q.push(tmp);
			}
		} 
	} 
	return 0;
}
int main(){
	int n,m,k;
	long long r;
	cin>>n>>m>>k>>r;
	int step = BFS(n,m,k,r);
	cout<<step;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

最佳损友1020

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值