-
この質問とCCF CSP-201409-4-最高のケータリング、CCF用CSP-201604-4-ゲームは似ていますが、トラバースBFS中最高のケータリングやゲームは、マップに似ている乗馬ボード、それはなります基板上の各点を通る層。
-
BFSは、この質問を横断しています条件付きトラバーサル:
1、走的是有定义(该点放置有无线路由器)的点(xi,yi)
2、半径在r之内
レコードの構造体の配列を使用する必要があるので图的信息
、構造が配列のインデックスによって表されます路由器的编号
。
- 注:long long型の使用をコーディネート!!!
(输入中所有的坐标的绝对值不超过 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;
}