## CCO '06 P2 - R & J

View as PDF

Points: 10
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Canadian Computing Competition: 2006 Stage 2, Day 1, Problem 2

Years ago, Romy and Jules were separated by their parents and forbidden to see each other ever again. However, using a tin-can telephone, their love survived and they were able to maintain their relationship. But, as time passed, some things changed and some things remained the same, Romy's great (times ) grand-child, Julia (from the planet Mars) is in love with Romian (from the planet Epsilon -Beta), but because of their parents' hatred is not able to speak with him.

To prevent Julia and Romian from seeing each other, their parents put them both on spaceships with no long-range communication facilities. Thus, Romian and Julia must use a laser to send each other messages using morse-code. In Romian and Julia's time, messages can be sent infinite distances through space using a laser, as long as the route between the sender and receiver is not blocked. Since this is the future, lasers can travel instantly across the universe. Therefore, you may assume that planets and spaceships remain stationary.

For this question, you are to determine whether Romian and Julia can communicate with each other (by laser) when given the -dimensional grid coordinates of their spaceships. The problem is that their communication laser is often blocked by intervening planets. Thus, they are truly star-crossed lovers.

#### Input Specification

For input you will be given, on two lines, the grid coordinates of Romian's and Julia's spaceships. Each coordinate will consist of three, whitespace separated, integer values. Then, following the locations of their spaceships, the input will consist of a line containing a single integer () indicating the number of planets in their current sector of space.

The coordinates of the planets follow on the next lines. Each planet is represented by integer values, separated by whitespace. The first three are the coordinates of the planet's centre and the fourth is the planet's radius. It may be helpful to know that a planet with centre and radius can be specified by the equation .

You may assume and that for any coordinate , .

You may also make the following assumptions:

Neither Romian or Juliet are within units of a planet (since they would crash into it), nor are they within a planet (since that is impossible).

Romian and Juliet do not occupy the same position in space (otherwise, their spaceships have crashed into each other and they will be consumed by an intergalactic explosion of epic proportions).

If the laser hits a planet, it would also have hit a planet with a radius which was units smaller. If the laser misses a planet, it would also have avoided a planet which was units larger.

#### Output Specification

As output, you are to print a single integer, the number of planets that block the laser.

#### Sample Input

100 100 100
-100 -100 -100
2
0 0 0 2
50 60 -50 5

#### Sample Output

1