TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

DartBoard

Problem statement, definition, constraints, and public examples.

Problem Statement

An electronic dartboard has been designed with evenly spaced concentric rings. Each ring has a score that is awarded when a dart lands in the ring. The dartboard senses the position where each dart lands and reports its x and y coordinate. We need to calculate the score.

The coordinate system of the dartboard has (0,0) at the center and the radius is 1000. So, for example, if there were four rings, a dart that landed within 250 of the center would be in the innermost ring, a dart that landed at a distance between 250 and 500 units from the center would be in the next ring, etc. A dart that lands farther than 1000 from the center is awarded a score of 0. If a dart lands exactly on the dividing line between rings, it is scored as if it had landed in the ring closer to the center.

Create a class DartBoard that contains a method score that is given a int[] x and a int[] y giving the coordinates of a player's dart throws and that is given a int[] ringValues that tells the scoring value of each ring. The method returns the total score from these throws.

The first elements of x and y give the coordinates of the first dart throw, the second elements correspond to the second throw, etc.

The first element of ringValues gives the value of the innermost ring, the second element gives the value of the next ring, etc. The number of elements in ringValues is the number of rings on the dartboard.

Definition

Class:
DartBoard
Method:
score
Parameters:
int[], int[], int[]
Returns:
int
Method signature:
int score(int[] x, int[] y, int[] ringValues)
(be sure your method is public)

Notes

  • The dividing line between two rings may not be at an integer radius. For example, if there are three rings, the dividing line between the innermost and the next ring would be at a radius of 333 1/3.

Constraints

  • x will contain between 1 and 5 elements inclusive
  • y will contain the same number of elements as x
  • each element of x and y will be between -2000 and 2000 inclusive
  • ringValues will contain between 1 and 10 elements inclusive
  • each element of ringValues will be between 0 and 100 inclusive

Examples

  1. {200,-30,30} 
    {200,200,1512}
    {100,50,25,10}
    Returns: 150
    The first dart lands at (200,200) which is not in the center ring but is in the next ring scoring a value of 50. The second dart lands at (-30,200) which is in the innermost (center) ring, scoring a value of 100. The third dart lands outside the scoring area, earning a score of 0. 50 + 100 + 0 = 150
  2. {0,0,2000} 
    {0,1000,0}
    {100,50,25,10}
    Returns: 110
    The first throw is dead center for 100 points. The next throw lands exactly on the outer boundary of the fourth ring earning 10 points. The third throw is wildly off target earning 0 points.
  3. {60,60,60,60,61}
    {80,80,80,80,80}
    {100,80,60,40,30,20,15,10,5,1}
    Returns: 480
    There are 10 rings, separated by radii 100,200,...,900. The first 4 darts all land at the same point, exactly 100 units away from the center, so they each earn 100 points. The last dart is just outside the innermost ring, so it earns 80 points.
Back to all problems