Connection Status:
Competition Arena > RadarFinder
SRM 349 · 2007-05-15 · by erinn · Geometry, Math
Class Name: RadarFinder
Return Type: int
Method Name: possibleLocations
Arg Types: (int, int, int, int, int, int)
Problem Statement

Problem Statement

You are the commander of a military operation that is focused on determining the location of an enemy unit. Two radar stations have provided measurements of their calculated distance from the enemy unit. You are given the locations of your radar stations in ints x1, y1 and x2, y2, and the calculated distances in ints r1 and r2, respectively.

You are to return an int indicating the number of possible locations of the enemy unit. If there are an infinite number of possible locations, return -1.

Constraints

  • x1 will be between -1000000000 and 1000000000, inclusive.
  • y1 will be between -1000000000 and 1000000000, inclusive.
  • r1 will be between 1 and 1000000000, inclusive.
  • x2 will be between -1000000000 and 1000000000, inclusive.
  • y2 will be between -1000000000 and 1000000000, inclusive.
  • r2 will be between 1 and 1000000000, inclusive.
Examples
0)
0
0
13
40
0
37
Returns: 2

The points (5, 12) and (5, -12) are the only points that are consistent with both radar measurements.

1)
0
0
3
0
7
4
Returns: 1

Only one point, (0, 3), is consistent with both measurements.

2)
0
0
5
10
10
3
Returns: 0

Perhaps one of the measurements was incorrect, since no points are consistent.

3)
0
0
1
0
0
1
Returns: -1

Getting two identical readings from the same location still leaves an unlimited number of possible locations.

4)
0
0
5
2
0
4
Returns: 2

Submissions are judged against all 304 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class RadarFinder with a public method int possibleLocations(int x1, int y1, int r1, int x2, int y2, int r2) · 304 test cases · 2 s / 256 MB per case

Submitting as anonymous