TopcoderArchive
Archive
Algorithm problem

GeneralElection

Problem statement, definition, constraints, and public examples.

Problem Statement

An election has just occurred. Given a int[] votes, where votes[i] is the number of votes for the ith candidate, you want to find the percentage of the total number of votes received by each candidate. If the percentage is not an integer, it must be rounded to an integer; you can choose to round up or down. You must make your choices in such a way that the sum of the percentages is exactly 100. Return the number of percentages for which you round up.

Definition

Class:
GeneralElection
Method:
numberOfRoundedUp
Parameters:
int[]
Returns:
int
Method signature:
int numberOfRoundedUp(int[] votes)
(be sure your method is public)

Constraints

  • votes will contain between 1 and 50 elements, inclusive.
  • Each element of votes will be between 1 and 1000, inclusive.

Examples

  1. {253, 253, 253, 241}
    Returns: 1
    The percentages are {25.3, 25.3, 25.3, 24.1}. If we round all the percentages down, the sum will be equal to 25 + 25 + 25 + 24 = 99. Therefore, one of the percentages must be rounded up.
  2. {2, 3}
    Returns: 0
    The raw percentages are 40.0 and 60.0. They are already integers.
  3. {500, 500}
    Returns: 0
    The raw percentages are 50.0 and 50.0. They are already integers.
  4. {1,2,3,4,5}
    Returns: 2
  5. {1000}
    Returns: 0
  6. {2,3,5,7,11,13,2,4,8,16}
    Returns: 5
Back to all problems