CCF의 CSP-201403-4- 무선 네트워크 (도 횡단 BFS)

1、走的是有定义(该点放置有无线路由器)的点(xi,yi)
2、半径在r之内

따라서 필요 레코드 구조의 배열을 사용하는 것으로 图的信息, 구조가 배열 인덱스에 의해 표현 路由器的编号.

  • 참고 : 오래 오래 입력 사용 좌표! ! !(输入中所有的坐标的绝对值不超过 108)

다음 코드는

#include<iostream>
#include<queue>
using namespace std;
const int N = 205;
struct node{
	long long x,y;
	int cross;
}map[N];
queue<node> q;
long long n,m,k,r;
bool vis[N];
int bfs(){
	vis[1] = true;
	q.push({map[1].x,map[1].y,0});
	while(!q.empty()){
		node cur = q.front();
		q.pop();
		if(cur.x==map[2].x&&cur.y==map[2].y) return cur.cross-1;
		for(int i = 1; i <= n+m; i++){
			if(vis[i]) continue;
			if((map[i].x-cur.x)*(map[i].x-cur.x)+(map[i].y-cur.y)*(map[i].y-cur.y)>r*r) continue;
			vis[i] = true;
			q.push({map[i].x,map[i].y,cur.cross+1});
		}
	}
}
int main()
{
	int x,y;
	cin >> n >> m >> k >> r;
	for(int i = 1; i <=m+n; i++){
		cin >> map[i].x >> map[i].y;
	}
	int ans = bfs();
	printf("%d\n", ans);
	return 0;
}
게시 된 123 개 원래 기사 · 원 찬양 774 ·은 30000 +를 볼

추천

출처blog.csdn.net/qq_42437577/article/details/104717063