struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
unordered_map<pair<int,int>, int, hash_pair> mp;
ll calc(ll x,ll y) {
return x * 1000000001 + y;
}
//拉链法
const int p = 999997;
int h[N],e[N],ne[N],idx;
void insert(int x) {
int k = (x % p + p) % p;
e[idx] = x;
ne[idx] = h[k];
h[k] = idx ++;
}
bool find(int x) {
int k = (x % p + p) % p;
for(int i=h[k];i!=-1;i=ne[i]) {
if(e[i] == x) return true;
}
return false;
}
int main(){
memset(h,-1,sizeof h);
...
}
//开放寻址法
const int null = 0x3f3f3f3f,p = 999997;
int h[N];
int find(int x) {
int k = (x % p + p) % p;
while(h[k] != null && h[k] != x) {
k ++;
if(k == N) k = 0;
}
return k;
}
int main(){
memset(h,0x3f,sizeof h);
...
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N = 999997;
typedef long long ll;
struct node{
int x,y,r,l;
}s[N];
ll id[N];
int res;
bool ins[N];
ll calc(ll x,ll y) {
return x * 1000000001 + y;
}
int find(ll x) {
int k = (x % N + N) % N;
while(id[k] != -1 && id[k] != x) {
k ++;
if(k == N) k = 0;
}
return k;
}
inline void dfs(ll a,ll b,ll c) {
for(ll i=a-c;i<=a+c;i++) {
for(ll j=b-c;j<=b+c;j++) {
ll x = (i - a) * (i - a);
ll y = (j - b) * (j - b);
if(x + y <= c * c) {
int T = find(calc(i,j));
if(id[T] != -1) {
if(ins[T]) continue;
ins[T] = true;
res += s[T].l;
dfs(s[T].x,s[T].y,s[T].r);
}
}
}
}
}
int main(){
int n,m,L = 0;
scanf("%d %d",&n,&m);
memset(id,-1,sizeof id);
for(int i=1;i<=n;i++) {
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int k = find(calc(a,b));
if(id[k] == -1) {
id[k] = calc(a,b);
s[k] = {a,b,c,0};
}
s[k].l ++;
s[k].r = max(s[k].r,c);
}
for(int i=0;i<m;i++) {
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
dfs(a,b,c);
}
printf("%d\n",res);
return 0;
}