Statistics

Problem Statement for "ImprovingStatistics"

Problem Statement

Several years ago I was playing Spider Solitaire on my computer all the time. Sometimes I won, sometimes I lost. Then I stopped playing Spider Solitaire and started participating in programming competitions. After a few years I happened to start my old solitaire program again. I was pleased to discover that with the skill I gained during the years I am now able to win each and every game of Spider Solitaire. However, the program still remembers some of my previous games and thus the statistics don't necessarily reflect my current perfect skills.

The program displays the statistics in the following way:
Games played: X
Games won: Y (Z %)

The number Z is the percentage of games I won, rounded down to the nearest integer. For example, if X=53 and Y=47, then Z=88.
(The value Y/X is roughly equal to 0.8868, which means that I won roughly 88.68% of the games I played. 88.68% rounded down to an integer is 88%.)

You will be given two ints played and won - the number of games I played so far, and the number of games I won so far. Return the smallest positive integer G such that if I now win G games in a row the displayed value of Z will increase. If this is impossible, return -1 instead.

Definition

Class:
ImprovingStatistics
Method:
howManyGames
Parameters:
int, int
Returns:
int
Method signature:
int howManyGames(int played, int won)
(be sure your method is public)

Notes

  • You may assume that the return value will always be less than 2,000,000,000.

Constraints

  • played will be between 1 and 1,000,000,000, inclusive.
  • won will be between 0 and played, inclusive.

Examples

  1. 10

    8

    Returns: 1

    So far I won 8 games out of 10, and thus the displayed success percentage is 80%. After I win the next game the percentage will increase to 81%.

  2. 100

    80

    Returns: 6

    Again, the currently displayed value is 80%. However, now I need to win at least 6 more games to bring it to 81%.

  3. 47

    47

    Returns: -1

    Nothing left to improve.

  4. 99000

    0

    Returns: 1000

  5. 1000000000

    470000000

    Returns: 19230770

  6. 999999

    999998

    Returns: -1

  7. 1000000000

    980000000

    Returns: 1000000000

  8. 1000000000

    974712345

    Returns: 264382750

  9. 1000000000

    979999999

    Returns: 50

  10. 999997473

    980123402

    Returns: 987409627

  11. 1

    0

    Returns: 1

  12. 1

    1

    Returns: -1

  13. 2

    0

    Returns: 1

  14. 2

    1

    Returns: 1

  15. 2

    2

    Returns: -1

  16. 3

    0

    Returns: 1

  17. 3

    1

    Returns: 1

  18. 3

    2

    Returns: 1

  19. 3

    3

    Returns: -1

  20. 32532

    3342

    Returns: 266

  21. 23532532

    3243243

    Returns: 59665

  22. 754754632

    52354643

    Returns: 514174

  23. 476432567

    0

    Returns: 4812451

  24. 987654321

    12

    Returns: 9976295

  25. 100

    99

    Returns: -1

  26. 1000000000

    980000000

    Returns: 1000000000

  27. 1000000000

    470000000

    Returns: 19230770

  28. 10

    0

    Returns: 1

  29. 1000000000

    990000000

    Returns: -1

  30. 1000000000

    999999999

    Returns: -1

  31. 10000

    9900

    Returns: -1

  32. 100000

    99999

    Returns: -1

  33. 200

    199

    Returns: -1

  34. 1000000000

    500000000

    Returns: 20408164

  35. 1000000000

    980000001

    Returns: 999999900

  36. 47

    46

    Returns: 3

  37. 1000

    9

    Returns: 2

  38. 1750

    1015

    Returns: 43

  39. 908533084

    907080095

    Returns: -1

  40. 1000000000

    989999999

    Returns: 100

  41. 147974666

    124825802

    Returns: 6351094

  42. 101

    100

    Returns: -1

  43. 99

    96

    Returns: 1

  44. 1000000000

    900000000

    Returns: 111111112

  45. 1000

    873

    Returns: 59

  46. 200

    198

    Returns: -1

  47. 222

    33

    Returns: 1

  48. 1000000000

    970000000

    Returns: 500000000

  49. 1000000000

    988000000

    Returns: 200000000

  50. 100

    98

    Returns: 100

  51. 100000

    98995

    Returns: 500

  52. 1000

    988

    Returns: 200

  53. 1000000000

    800000000

    Returns: 52631579

  54. 1000

    998

    Returns: -1

  55. 10

    1

    Returns: 1

  56. 1000000

    999999

    Returns: -1

  57. 1000000000

    3

    Returns: 10101008

  58. 10000

    9999

    Returns: -1

  59. 10000000

    9999999

    Returns: -1

  60. 436134623

    394732463

    Returns: 23889377

  61. 1000000000

    470000001

    Returns: 19230768

  62. 999999999

    980000000

    Returns: 999999901

  63. 1000000000

    0

    Returns: 10101011

  64. 999999999

    999999998

    Returns: -1

  65. 500000

    88888

    Returns: 1357

  66. 1000

    999

    Returns: -1

  67. 843090428

    556970660

    Returns: 23939172

  68. 1000000000

    989000000

    Returns: 100000000

  69. 1

    0

    Returns: 1

  70. 2

    1

    Returns: 1

  71. 999

    55

    Returns: 6

  72. 10

    10

    Returns: -1

  73. 199999999

    199999998

    Returns: -1

  74. 1000000000

    570000000

    Returns: 23809524

  75. 5

    1

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: