提交时间:2024-03-31 13:37:19

运行 ID: 27889

#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define m_p make_pair #define double long double #define int long long using namespace std; typedef long long ll; const int maxn=5e4+10; inline ll read(){ ll x=0;short t=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')t=-1;ch=getchar(); }while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,m,fa[maxn]; int find(int x){ if(x==fa[x])return x; return fa[x]=find(fa[x]); } bool flg[maxn]; struct node { int x,y,r; }d[maxn]; int Px[maxn],Py[maxn]; inline pair<int,pair<double,double> > calc(double a,double b,double c){ double delta=b*b-4*a*c; //cerr<<"delta = "<<delta<<'\n'; if(delta<0)return m_p(0,m_p(-1,-1)); delta=sqrt(delta); double x=(-b+delta)/2.0/a; double y=(-b-delta)/2.0/a; //cerr<<"sol = "<<x<<' '<<y<<'\n'; return m_p(1,m_p(x,y)); } inline pair<double,double> get(double xa,double ya,double xb,double yb){ double k=(yb-ya)/(xb-xa); double b=ya-k*xa; return m_p(k,b); } inline bool chk_(double k,double b,double l,double r,int x){ double a=1+k*k; double bb=-2*d[x].x+2*k*b-2*k*d[x].y; double c=d[x].x*d[x].x+d[x].y*d[x].y+b*b-2*b*d[x].y-d[x].r*d[x].r; auto it=calc(a,bb,c); if(it.p1==0)return 1; //cerr<<"??? "<<it.p2.p1<<' '<<it.p2.p2<<' '<<l<<' '<<r<<'\n'; if(it.p2.p1>=l&&it.p2.p1<=r)return 0; if(it.p2.p2>=l&&it.p2.p2<=r)return 0; return 1; } inline bool chk(int x,int y,int r){ if(Px[y]==Px[x]){ double a=1; double b=-2*d[r].y; double c=d[r].x*d[r].x+Px[x]*Px[x]-2*d[r].x*Px[x]+d[r].y*d[r].y-d[r].r*d[r].r; auto it=calc(a,b,c); if(it.p1==0)return 0; double l=min(Py[x],Py[y]); double r=max(Py[x],Py[y]); if(it.p2.p1>=l&&it.p2.p1<=r)return 0; if(it.p2.p2>=l&&it.p2.p2<=r)return 0; return 1; } auto it=get(Px[x],Py[x],Px[y],Py[y]); double k=it.p1,b=it.p2; //cerr<<"test "<<k<<' '<<b<<'\n'; return chk_(k,b,min(Px[x],Px[y]),max(Px[x],Px[y]),r); } void slv(){ n=read(),m=read(); up(i,1,n)fa[i]=i; up(i,1,n)Px[i]=read(),Py[i]=read(); up(i,1,m)d[i].x=read(),d[i].y=read(),d[i].r=read(); int res=n-1; up(i,1,n){ if(flg[i])continue; up(j,i+1,n)if(find(i)!=find(j)&&(!flg[j])){ bool f=1; up(k,1,m)if(!chk(i,j,k)){f=0;break;} if(f){ //cerr<<Px[i]<<' '<<Py[i]<<' '<<Px[j]<<' '<<Py[j]<<'\n'; //cerr<<"! "<<i<<' '<<j<<'\n'; fa[find(i)]=find(j);res--; } } } printf("%d\n",res); } signed main(){ // freopen("beacons.in","r",stdin); // freopen("beacons.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }