Contest Hunter Round #46 Magnetic block

Source: Internet
Author: User

Describe

In a vast expanse of wilderness, strewn with n pieces of magnets. The properties of each magnet can be described in a five-tuple (x,y,m,p,r), where the x,y represents its coordinates, m is the mass of the magnet, p is the magnetic force, and R is the suction radius. If the distance between the magnet A and the magnet B is not greater than the attraction radius of the magnet A, and the mass of the magnet B is not greater than the magnetic force of the magnet A, then a can attract B.
Small take wine with a piece of their own magnet L came to the field (X0,Y0), we can be regarded as the coordinates of the magnetic L (x0,y0). Small fetch wine holding magnet L and keep in place, all can be attracted by L Magnet will be attracted to come. At every moment, he could choose to replace any of the magnets he had obtained (or, of course, the L magnets he had originally carried) to attract more magnets (x0,y0). Small fetch wine wants to know, he can obtain how many pieces of magnet at most.
Input format

The first line of five integers x0,y0,pl,rl,n, indicating the location of the wine, Magnet l magnetic force, attraction radius and the number of magnets scattered on the field.
The next n rows are five integers per line x,y,m,p,r, describing the nature of a magnet. Output format

Output An integer that represents the maximum number of scattered magnets available (not including the original magnet L).

Divide all the stones into sqrt (n) blocks according to the quality, each of which is sorted by distance.
When using a stone, find all the pieces of the mass that are less than the current magnetic force, and then take away the same amount of violence that is required to meet the requirements in order.
The whole operation can be divided into two parts, taking the whole block and taking the incomplete. For the whole block, look for an O (sqrt (n)) time, a total of looking for O (n) times. Each block is only taken once, with a total of O (n) times. More out of a paragraph, each time violence O (sqrt (n)), violence O (n) times. So the total complexity O (n*sqrt (n)).

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define LL Long
using namespace Std;
const double eps=1e-6;
    struct Rock {int m,p,r;
Double D;
}A[250010];
    Int Rd () {int x=0,f=1;
    Char C=getchar (); while (c< ' 0 ' | |
    C> ' 9 ') &&c!= '-') C=getchar ();
        if (c== '-') {f=-1;
    C=getchar ();
        while (c>= ' 0 ' &&c<= ' 9 ') {x=x*10+c-' 0 ';
    C=getchar ();
return x*f; BOOL CMPM (const rock &r1,const-&AMP;R2) {return r1.m<r2.m;} bool Cmpd (const rock &r1,const Rock &A
MP;R2) {return r1.d<r2.d;} bool out[250010];
int l[510],r[510],maxm[510],to[510],n,tot,que[250010];
    int main () {int i,j,k,m,n,p,q,x0,y0,hd,tl,ans=0;
    Double x,y,z;
    X0=rd ();
    Y0=rd ();
    A[0].p=rd ();
    A[0].r=rd ();
    N=rd ();
        for (i=1;i<=n;i++) {p=rd ();
        Q=rd ();
        A[i].m=rd ();
        A[i].p=rd (); A[i].r=rd();
    A[i].d=sqrt (LL) (p-x0) * (p-x0) + (LL) (q-y0) * (q-y0) +0.0);
    Sort (A+1,A+N+1,CMPM);
    TOT=SQRT (n+0.1);
        for (i=1;i<=tot;i++) {l[i]=r[i-1]+1;
        To[i]=l[i]-1;
        R[i]= i==tot?n:l[i]+tot-1;
    MAXM[I]=A[R[I]].M;
    for (i=1;i<=tot;i++) sort (A+L[I],A+R[I]+1,CMPD);
    hd=tl=1;
        while (HD&LT;=TL) {p=que[hd++]; for (i=1;i<=tot&&maxm[i]<=a[p].p;i++) {while (to[i]<r[i]&&a[to[i]+1].d<=e
                PS+A[P].R) {to[i]++;
                    if (!out[to[i]]) {que[++tl]=to[i];
                    ans++;
                Out[to[i]]=1; }} if (I<=tot) for (j=to[i]+1;j<=r[i];j++) if (OUT[J]==0&AMP;&A
                MP;A[J].D&LT;=EPS+A[P].R&AMP;&AMP;A[J].M&LT;=A[P].P) {out[j]=1;
                ans++; Que[++tl]=j;
} printf ("%d\n", ans); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.