Celestial Map
Time limit2sMemory limit512 MB
Count stars that, d years ago, lay in a plane through the origin and were exactly d from the origin.
- Level
Medium4 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
Bob works at a center for interplanetary communication. Today a signal from an unknown civilization reached his station. Panel 42 should show the coordinates of the point the signal came from, but instead it shows two vectors, one number, and the warning code 54816. The manual explains the code: computing the exact coordinates failed, so the station computed the plane the signal came from together with the distance to its origin.
Bob sits at the origin . The two given vectors start there and span a plane. The number is the distance from Bob to the point the signal came from. A signal travels at the speed of light, so a signal arriving now was sent years ago, and at that moment the star that sent it was inside the plane and at distance exactly from the origin.
Humanity has a complete map of every star: the current position of each star and the constant velocity vector along which it travels. Bob wants to plan his afternoon, so he first wants to know how many stars he has to check by hand. Count the stars that were inside the given plane and at distance exactly from the origin exactly years ago.
Input
The first line contains an integer and a real number (, ), where is the number of stars in the universe and is the distance from Bob to the point the signal came from.
Each of the next two lines contains three real numbers , , and (, ). The two vectors are not parallel and they span a plane through Bob's location. The point the signal came from was inside that plane when the signal was sent.
The next lines describe the stars, two lines per star.
- The first line contains three real numbers , , and (). is the current position of the star.
- The second line contains three real numbers , , and (). is the trajectory of the star, and is the speed at which it travels.
You can assume the following.
- The other civilization's signal travels at the speed of light.
- All speeds are given in lightyears per year, and all distances are in lightyears.
- Bob's location is fixed at .
- Stars never collide.
- Among the points where the given plane meets a star trajectory, none is at distance lightyears from the origin except for points at distance exactly lightyears.
- A star that was not inside the plane at the time the signal was sent was at least 0.1 lightyears away from the plane.
- Every trajectory meets the given plane at an angle between 10 and 90 degrees.
Output
Print the number of stars that fit the description.
Note
The first example has 2 stars. The current star positions, the given plane, and the two trajectories are shown in figure 1. The plane the signal came from is spanned by the vectors and , and the distance is . The first star is currently at and moves in direction at speed . The second star is currently at and moves in the same direction at speed . Moving both stars back by two years gives the positions in figure 2. Star 1 is inside the plane and its distance to Bob is , so it fits the description. Star 2 is not inside the plane, so it does not fit. The answer for the first example is 1.

Figure 1: star positions in the present for the first example.

Figure 2: star positions two years ago for the first example.