Statistics

Problem Statement for "TVSize"

Problem Statement

When shopping for TVs consumers may notice that a TV's size is given by its diagonal in inches. The aspect ratio of a screen is the ratio of its width to its height. Given the aspect ratio and the diagonal size in inches of a TV screen, you must compute its width and height in inches (see the notes and the first example for more information). If the width or the height is not an integer, round down to the nearest integer; for example, 1.7 would become 1.

You are tasked with writing a method which accepts 3 arguments: an int diagonal specifying the TV's diagonal in inches, an int height specifying the aspect ratio height, and an int width specifying the aspect ratio width. Your program should compute the actual height and width of the TV in inches and return them in a int[] where the first element is the TV's height and the second element is the TV's width.

Definition

Class:
TVSize
Method:
calcSize
Parameters:
int, int, int
Returns:
int[]
Method signature:
int[] calcSize(int diagonal, int height, int width)
(be sure your method is public)

Notes

  • Let W denote the width, H denote the height and D denote the diagonal of the screen. Then W*W + H*H = D*D and W * height = H * width.

Constraints

  • diagonal will be between 5 and 1000, inclusive.
  • height will be between 1 and 99, inclusive.
  • width will be between 2 and 100, inclusive.
  • width will be greater than height.

Examples

  1. 52

    9

    16

    Returns: {25, 45 }

    W = (width/height) * H D*D = W*W + H*H 52^2 = (width/height)^2 * H^2 + H^2 52^2 = (16/9)^2 * H^2 + H^2 H = 25.49 W = 45.32

  2. 7

    2

    3

    Returns: {3, 5 }

  3. 13

    7

    10

    Returns: {7, 10 }

  4. 7

    32

    47

    Returns: {3, 5 }

  5. 11

    15

    16

    Returns: {7, 8 }

  6. 103

    9

    16

    Returns: {50, 89 }

  7. 36

    3

    4

    Returns: {21, 28 }

  8. 1000

    99

    100

    Returns: {703, 710 }

  9. 22

    1

    2

    Returns: {9, 19 }

  10. 23

    34

    35

    Returns: {16, 16 }

  11. 256

    99

    100

    Returns: {180, 181 }

  12. 17

    1

    2

    Returns: {7, 15 }

  13. 888

    8

    100

    Returns: {70, 885 }

  14. 231

    1

    100

    Returns: {2, 230 }

  15. 100

    99

    100

    Returns: {70, 71 }

  16. 5

    99

    100

    Returns: {3, 3 }

  17. 1000

    1

    2

    Returns: {447, 894 }

  18. 500

    50

    51

    Returns: {350, 357 }

  19. 666

    3

    5

    Returns: {342, 571 }

  20. 10

    5

    8

    Returns: {5, 8 }

  21. 83

    22

    87

    Returns: {20, 80 }

  22. 775

    63

    80

    Returns: {479, 608 }

  23. 169

    13

    26

    Returns: {75, 151 }

  24. 144

    1

    4

    Returns: {34, 139 }

  25. 211

    43

    47

    Returns: {142, 155 }

  26. 818

    69

    96

    Returns: {477, 664 }

  27. 513

    11

    12

    Returns: {346, 378 }

  28. 967

    96

    97

    Returns: {680, 687 }

  29. 333

    30

    37

    Returns: {209, 258 }

  30. 97

    2

    99

    Returns: {1, 96 }

  31. 101

    10

    100

    Returns: {10, 100 }

  32. 5

    1

    2

    Returns: {2, 4 }

  33. 5

    3

    4

    Returns: {3, 4 }

  34. 1000

    99

    100

    Returns: {703, 710 }

  35. 377

    25

    60

    Returns: {145, 348 }

  36. 291

    65

    72

    Returns: {195, 216 }

  37. 679

    65

    72

    Returns: {455, 504 }


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: