hiho一下 第124周 查找附近POI- 四叉樹

題解說用四叉樹,沒分析複雜度:

恩。四叉樹:

以下代碼跑得比部分四叉樹代碼還快

#include<bits/stdc++.h>
using namespace std;

struct point{
	int x;
	int y;
};
point p[50000];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
    scanf("%d%d",&p[i].x,&p[i].y);
    int x,y,r;
    for(int i=1;i<=m;i++)
    {
        int ans=0;
        scanf("%d%d%d",&x,&y,&r);
        for(int j=1;j<=n;j++)
        if (r*r>= (x-p[j].x)*(x-p[j].x)+(y-p[j].y)*(y-p[j].y) )
        ans++;
        printf("%d\n",ans);
    }


	return 0;
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章