UVA1 - Radiation

no tags 

Nuclear power plants (NPP) are a blessing and curse of modern civilization. NPPs have some risks but still it is one of the cheapest ways to produce electricity in the developed world. In this problem we will discuss a situation related to two nuclear plants, which are not far away from each other.

We will describe the entire scenario in a at land, so two-dimensional Cartesian coordinate system is used to denote each location. Lets assume that the coordinate of the two nuclear power plants are (ax; ay) and (bx; by). Houses that are located within distance R1 (inclusive) of the power plant at (ax; ay) are under high risk of radiation. Similarly, houses that are located within distance R2 (inclusive) of the power plant at (bx; by) are under high risk of radiation. So the authorities of power plant 1 and power plant 2 distribute special protective equipment to the houses that are within radius (inclusive) R1 and R2 of the respective power plants. As a result each of the houses that are endangered by both the plants actually receive two sets of equipment to protect their house.

Given the location of the houses and the values of ax; ay; bx; by and possible values of R1 and R2 your job is to find out the number of houses that are endangered by both the plants

Input

The input file contains at most 3 test cases. The description of each test case is given below:

A test case starts with a line containing a positive integer N (0 < N <= 200000) that denotes the number of houses that are under either low risk or high risk of radiation. Each of the next N lines contains two integers xi, yi  (0 <= xi, yi <= 20000) that denotes the coordinate of the i-th house.

No two houses are at the same location. The next line contains five integers ax, ay, bx, by and q (0 <= ax, ay, bx, by <= 20000, 0 < q <= 20000). The meaning of ax, ay, bx and by are given in the problem statement. Here q denotes the total number of query. Each of the next q lines contains two integers, which denote the values of R1 and R2 (0 < R1, R2 <= 13000) respectively.

A line containing a single zero terminates input. This line should not be processed.

Output

For each test case produce q+ 1 lines of output. The first line is the serial of output. For each query (given value of R1 and R2) determine the number of houses that are endangered by both the plants. You may consider using faster IO as judge input file is large.

Note: First query in the sample input corresponds to Figure 1.

Example

Input:
11
95 75
27 6
93 5
124 13
34 49
65 61
81 49
77 33
110 50
91 22
110 25
57 42 97 36 1
31 25
0

Output:
Case 1:
2

hide comments
(Tjandra Satria Gunawan)(曾毅昆): 2015-02-17 02:15:15

@zukow: Thanks for the hint, second best for now ;-)

:D: 2015-02-16 21:28:05

Some hints:
You can solve entire problem using 32bit integers ONLY.
Low limits for R1 and R2 are very useful when considering optimizations.
Fast I/O is actually not critical here. I had 0.14s with scanf/printf.

(abdou, moderators: please feel to delete/hide this comment if you find it being to much of a spoiler).

Min_25: 2014-12-06 08:07:41

@abdou_93
Could you restore the image file by uploading it to your account ?

>> (the link to image: http://i.imgur.com/a3T2Ctd.png)

(reply by Min_25)
I snipped the link to the image. Since the link to Figure1 is no longer available and we cannot see it, please fix the link by uploading the image file to your account using "upload files" (http://www.spoj.com/uploads/).

Edit:
I uploaded the image file to my account and edited the html.

>>@Min_25.thanks for uploading image

Last edit: 2014-12-06 08:24:03
Dinesh Agarwal: 2014-12-06 08:07:41

Where and what's wrong in my solution??

IIAvinashKhareII: 2014-12-06 08:07:41

can anyone tell me what will work here beyond d normal mathematics..

Prasun Joshi: 2014-12-06 08:07:41

tle even after using fast IO!
abdou 00 : pls tell me where m i wrong?

Last edit: 2014-03-20 05:11:35
abdou_93: 2014-12-06 08:07:41

@Jacob Plachta.. congratulation you the first one


Added by:abdou_93
Date:2014-03-01
Time limit:3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64