With Bessie as the reference, Bessie was fixed at the origin, and each killer was a circle in the center of a ray.
Solve the time interval where each killer can shoot Bessie, and then scan the line, time complexity $o (n\log N) $.
#include <cstdio> #include <algorithm> #include <cmath>using namespace std;typedef long Long ll;int n,r , bx,by,bvx,bvy,x,y,vx,vy,i,m,t,ans;double l,r,inf=1e9;struct p{double x;int y; P () {}p (double _x,int _y) {x=_x,y=_y;}} a[100010];inline BOOL CMP (P a,p b) {return a.x<b.x;} inline void Getlr (ll a,ll b,ll c) { if (!a) { if (c<=0) L=0,r=inf;else L=r=-inf; return; } ll D=b*b-a*c*4; if (d<0) {L=r=-inf;return;} L= ( -1.0*b-sqrt (d))/2/a,r= ( -1.0*b+sqrt (d))/2/a; if (r<0) L=r=-inf; if (l<0) l=0;} int main () { scanf ("%d%d%d%d%d%d", &n,&r,&bx,&by,&bvx,&bvy); while (n--) { scanf ("%d%d%d%d", &x,&y,&vx,&vy); X-=bx,y-=by,vx-=bvx,vy-=bvy; GETLR (vx*vx+vy*vy,2* (X*vx+y*vy), x*x+y*y-r*r); if (r>-1) a[++m]=p (l,1), a[++m]=p (r,-1); } Sort (a+1,a+m+1,cmp); for (i=1;i<=m;i++) Ans=max (ANS,T+=A[I].Y); Return printf ("%d", ans), 0;}
BZOJ1580: [Usaco2009 hol]cattle bruisers Killer game