请求加强数据
查看原帖
请求加强数据
178992
Hanghang楼主2023/2/10 08:57

写的k-d树挂了,就写了发暴力,结果就过了

AC代码:

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

typedef long long ll;
const int N=1e6+3;
int n,m;
struct Node{int x,y;}a[N];
struct Nod
{
    ll d,id;
    bool operator <(Nod a)const{return a.d!=d?a.d<d:a.id>id;}
};
priority_queue<Nod>q;
ll Pow(ll x){return x*x;}
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("baoli.out","w",stdout);
	cin>>n;int s=0;
	for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y;
	cin>>m;
	while(m--)
	{
		ll x,y,k;cin>>x>>y>>k;
		while(!q.empty())q.pop();
		for(int i=1;i<=k;i++)q.push({-1,0});
		for(int i=1;i<=n;i++)
		{
			ll d=Pow(a[i].x-x)+Pow(a[i].y-y);
			if(d>q.top().d||(d==q.top().d&&i<q.top().id))q.pop(),q.push({d,i});
		}
		cout<<q.top().id<<endl;
	}
}
2023/2/10 08:57
加载中...