Statistics

Problem Statement for "Pancakes"

Problem Statement

You have a stove and P pancake pans. The stove has enough heaters to use all pans at the same time.

You want to make N pancakes. Each pancake must be cooked for exactly two minutes: one minute from one side and then one minute from the other side.


We will measure the time in minutes since you start cooking. During each minute, each pan must either be unused or it must contain one of the pancakes. If a pan contains a pancake, the bottom side of the pancake is being cooked.

We will assume that at the beginning/end of each minute you can instantly perform all the necessary actions: getting some pancakes into pans, taking some pancakes out of pans, and flipping some pancakes over (either in the same pan or into a different pan).


Produce one possible schedule to cook all N pancakes in as few minutes as possible. Return the schedule as a String[]. Each element should describe one minute. Each element should have P characters: one for each pan. Use the character '-' to denote an empty pan. Use the first N English letters to describe the pancakes: the uppercase letter is one side being cooked and the corresponding lowercase letter the other side of the same pancake. (See the examples.)

Any valid cooking schedule that minimizes the number of minutes needed will be accepted.

Definition

Class:
Pancakes
Method:
makePancakes
Parameters:
int, int
Returns:
String[]
Method signature:
String[] makePancakes(int N, int P)
(be sure your method is public)

Constraints

  • N will be between 1 and 26, inclusive.
  • P will be between 1 and 26, inclusive.

Examples

  1. 1

    3

    Returns: {"A--", "-a-" }

    N = 1 means we want a single pancake. P = 3 means we have three pans. The preparation will take two minutes, because it's not possible to cook the pancake from both sides at the same time. Having more than one pan does not help us. Two of the three pans will remain unused each minute. In the example output we used a different pan during the second minute. This is allowed but not necessary. E.g., {"--a", "--A"} is another valid output for this test case, and in that output we use the same pan for both sides of the pancake.

  2. 3

    1

    Returns: {"A", "c", "B", "C", "a", "b" }

    We want three pancakes and we only have a single pan. This time the cooking will clearly take us six minutes. Note that the order in which we cook does not matter. In particular, it is not necessary to cook both sides of a pancake immediately one after another. A pancake can sit and wait with just one side cooked for arbitrarily many minutes.

  3. 5

    4

    Returns: {"bA-e", "ECad", "-BcD" }

    Given four pans, a naive solution needs four minutes to prepare five pancakes: cook four of them from one side, then cook them from the other side, and in the next two minutes do the same with the fifth pancake. However, if we are smart and schedule everything properly, it is possible to prepare five pancakes in only three minutes.

  4. 1

    1

    Returns: {"A", "a" }

  5. 1

    17

    Returns: {"A----------------", "a----------------" }

  6. 2

    1

    Returns: {"A", "B", "a", "b" }

  7. 2

    2

    Returns: {"AB", "ab" }

  8. 2

    3

    Returns: {"AB-", "ab-" }

  9. 3

    2

    Returns: {"AB", "Ca", "bc" }

  10. 4

    1

    Returns: {"A", "B", "C", "D", "a", "b", "c", "d" }

  11. 4

    2

    Returns: {"AB", "CD", "ab", "cd" }

  12. 4

    3

    Returns: {"ABC", "Dab", "cd-" }

  13. 5

    1

    Returns: {"A", "B", "C", "D", "E", "a", "b", "c", "d", "e" }

  14. 5

    2

    Returns: {"AB", "CD", "Ea", "bc", "de" }

  15. 5

    3

    Returns: {"ABC", "DEa", "bcd", "e--" }

  16. 5

    4

    Returns: {"bA-e", "ECad", "-BcD" }

  17. 6

    1

    Returns: {"A", "B", "C", "D", "E", "F", "a", "b", "c", "d", "e", "f" }

  18. 6

    2

    Returns: {"AB", "CD", "EF", "ab", "cd", "ef" }

  19. 6

    3

    Returns: {"ABC", "DEF", "abc", "def" }

  20. 6

    4

    Returns: {"ABCD", "EFab", "cdef" }

  21. 6

    5

    Returns: {"ABCDE", "Fabcd", "ef---" }

  22. 7

    1

    Returns: {"A", "B", "C", "D", "E", "F", "G", "a", "b", "c", "d", "e", "f", "g" }

  23. 7

    2

    Returns: {"AB", "CD", "EF", "Ga", "bc", "de", "fg" }

  24. 7

    3

    Returns: {"ABC", "DEF", "Gab", "cde", "fg-" }

  25. 7

    4

    Returns: {"ABCD", "EFGa", "bcde", "fg--" }

  26. 7

    5

    Returns: {"ABCDE", "FGabc", "defg-" }

  27. 7

    6

    Returns: {"ABCDEF", "Gabcde", "fg----" }

  28. 7

    7

    Returns: {"ABCDEFG", "abcdefg" }

  29. 7

    17

    Returns: {"ABCDEFG----------", "abcdefg----------" }

  30. 8

    1

    Returns: {"A", "B", "C", "D", "E", "F", "G", "H", "a", "b", "c", "d", "e", "f", "g", "h" }

  31. 8

    2

    Returns: {"AB", "CD", "EF", "GH", "ab", "cd", "ef", "gh" }

  32. 8

    3

    Returns: {"ABC", "DEF", "GHa", "bcd", "efg", "h--" }

  33. 8

    4

    Returns: {"ABCD", "EFGH", "abcd", "efgh" }

  34. 8

    5

    Returns: {"ABCDE", "FGHab", "cdefg", "h----" }

  35. 8

    6

    Returns: {"ABCDEF", "GHabcd", "efgh--" }

  36. 8

    7

    Returns: {"ABCDEFG", "Habcdef", "gh-----" }

  37. 9

    1

    Returns: {"A", "B", "C", "D", "E", "F", "G", "H", "I", "a", "b", "c", "d", "e", "f", "g", "h", "i" }

  38. 9

    2

    Returns: {"AB", "CD", "EF", "GH", "Ia", "bc", "de", "fg", "hi" }

  39. 9

    3

    Returns: {"ABC", "DEF", "GHI", "abc", "def", "ghi" }

  40. 9

    4

    Returns: {"ABCD", "EFGH", "Iabc", "defg", "hi--" }

  41. 9

    5

    Returns: {"ABCDE", "FGHIa", "bcdef", "ghi--" }

  42. 9

    6

    Returns: {"ABCDEF", "GHIabc", "defghi" }

  43. 9

    7

    Returns: {"ABCDEFG", "HIabcde", "fghi---" }

  44. 9

    8

    Returns: {"ABCDEFGH", "Iabcdefg", "hi------" }

  45. 10

    2

    Returns: {"AB", "CD", "EF", "GH", "IJ", "ab", "cd", "ef", "gh", "ij" }

  46. 10

    5

    Returns: {"ABCDE", "FGHIJ", "abcde", "fghij" }

  47. 10

    6

    Returns: {"ABCDEF", "GHIJab", "cdefgh", "ij----" }

  48. 11

    3

    Returns: {"ABC", "DEF", "GHI", "JKa", "bcd", "efg", "hij", "k--" }

  49. 11

    7

    Returns: {"ABCDEFG", "HIJKabc", "defghij", "k------" }

  50. 11

    8

    Returns: {"ABCDEFGH", "IJKabcde", "fghijk--" }

  51. 11

    9

    Returns: {"ABCDEFGHI", "JKabcdefg", "hijk-----" }

  52. 13

    7

    Returns: {"ABCDEFG", "HIJKLMa", "bcdefgh", "ijklm--" }

  53. 16

    4

    Returns: {"ABCD", "EFGH", "IJKL", "MNOP", "abcd", "efgh", "ijkl", "mnop" }

  54. 16

    8

    Returns: {"ABCDEFGH", "IJKLMNOP", "abcdefgh", "ijklmnop" }

  55. 17

    9

    Returns: {"ABCDEFGHI", "JKLMNOPQa", "bcdefghij", "klmnopq--" }

  56. 17

    11

    Returns: {"ABCDEFGHIJK", "LMNOPQabcde", "fghijklmnop", "q----------" }

  57. 17

    12

    Returns: {"ABCDEFGHIJKL", "MNOPQabcdefg", "hijklmnopq--" }

  58. 18

    4

    Returns: {"ABCD", "EFGH", "IJKL", "MNOP", "QRab", "cdef", "ghij", "klmn", "opqr" }

  59. 18

    18

    Returns: {"ABCDEFGHIJKLMNOPQR", "abcdefghijklmnopqr" }

  60. 19

    13

    Returns: {"ABCDEFGHIJKLM", "NOPQRSabcdefg", "hijklmnopqrs-" }

  61. 20

    4

    Returns: {"ABCD", "EFGH", "IJKL", "MNOP", "QRST", "abcd", "efgh", "ijkl", "mnop", "qrst" }

  62. 20

    9

    Returns: {"ABCDEFGHI", "JKLMNOPQR", "STabcdefg", "hijklmnop", "qrst-----" }

  63. 20

    18

    Returns: {"ABCDEFGHIJKLMNOPQR", "STabcdefghijklmnop", "qrst--------------" }

  64. 21

    3

    Returns: {"ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "abc", "def", "ghi", "jkl", "mno", "pqr", "stu" }

  65. 21

    10

    Returns: {"ABCDEFGHIJ", "KLMNOPQRST", "Uabcdefghi", "jklmnopqrs", "tu--------" }

  66. 21

    12

    Returns: {"ABCDEFGHIJKL", "MNOPQRSTUabc", "defghijklmno", "pqrstu------" }

  67. 21

    18

    Returns: {"ABCDEFGHIJKLMNOPQR", "STUabcdefghijklmno", "pqrstu------------" }

  68. 21

    19

    Returns: {"ABCDEFGHIJKLMNOPQRS", "TUabcdefghijklmnopq", "rstu---------------" }

  69. 22

    13

    Returns: {"ABCDEFGHIJKLM", "NOPQRSTUVabcd", "efghijklmnopq", "rstuv--------" }

  70. 22

    17

    Returns: {"ABCDEFGHIJKLMNOPQ", "RSTUVabcdefghijkl", "mnopqrstuv-------" }

  71. 23

    8

    Returns: {"ABCDEFGH", "IJKLMNOP", "QRSTUVWa", "bcdefghi", "jklmnopq", "rstuvw--" }

  72. 23

    18

    Returns: {"ABCDEFGHIJKLMNOPQR", "STUVWabcdefghijklm", "nopqrstuvw--------" }

  73. 23

    25

    Returns: {"ABCDEFGHIJKLMNOPQRSTUVW--", "abcdefghijklmnopqrstuvw--" }

  74. 24

    8

    Returns: {"ABCDEFGH", "IJKLMNOP", "QRSTUVWX", "abcdefgh", "ijklmnop", "qrstuvwx" }

  75. 24

    19

    Returns: {"ABCDEFGHIJKLMNOPQRS", "TUVWXabcdefghijklmn", "opqrstuvwx---------" }

  76. 25

    24

    Returns: {"ABCDEFGHIJKLMNOPQRSTUVWX", "Yabcdefghijklmnopqrstuvw", "xy----------------------" }

  77. 26

    1

    Returns: {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }

  78. 26

    2

    Returns: {"AB", "CD", "EF", "GH", "IJ", "KL", "MN", "OP", "QR", "ST", "UV", "WX", "YZ", "ab", "cd", "ef", "gh", "ij", "kl", "mn", "op", "qr", "st", "uv", "wx", "yz" }

  79. 26

    3

    Returns: {"ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VWX", "YZa", "bcd", "efg", "hij", "klm", "nop", "qrs", "tuv", "wxy", "z--" }

  80. 26

    4

    Returns: {"ABCD", "EFGH", "IJKL", "MNOP", "QRST", "UVWX", "YZab", "cdef", "ghij", "klmn", "opqr", "stuv", "wxyz" }

  81. 26

    5

    Returns: {"ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "Zabcd", "efghi", "jklmn", "opqrs", "tuvwx", "yz---" }

  82. 26

    6

    Returns: {"ABCDEF", "GHIJKL", "MNOPQR", "STUVWX", "YZabcd", "efghij", "klmnop", "qrstuv", "wxyz--" }

  83. 26

    7

    Returns: {"ABCDEFG", "HIJKLMN", "OPQRSTU", "VWXYZab", "cdefghi", "jklmnop", "qrstuvw", "xyz----" }

  84. 26

    8

    Returns: {"ABCDEFGH", "IJKLMNOP", "QRSTUVWX", "YZabcdef", "ghijklmn", "opqrstuv", "wxyz----" }

  85. 26

    9

    Returns: {"ABCDEFGHI", "JKLMNOPQR", "STUVWXYZa", "bcdefghij", "klmnopqrs", "tuvwxyz--" }

  86. 26

    10

    Returns: {"ABCDEFGHIJ", "KLMNOPQRST", "UVWXYZabcd", "efghijklmn", "opqrstuvwx", "yz--------" }

  87. 26

    11

    Returns: {"ABCDEFGHIJK", "LMNOPQRSTUV", "WXYZabcdefg", "hijklmnopqr", "stuvwxyz---" }

  88. 26

    12

    Returns: {"ABCDEFGHIJKL", "MNOPQRSTUVWX", "YZabcdefghij", "klmnopqrstuv", "wxyz--------" }

  89. 26

    13

    Returns: {"ABCDEFGHIJKLM", "NOPQRSTUVWXYZ", "abcdefghijklm", "nopqrstuvwxyz" }

  90. 26

    14

    Returns: {"ABCDEFGHIJKLMN", "OPQRSTUVWXYZab", "cdefghijklmnop", "qrstuvwxyz----" }

  91. 26

    15

    Returns: {"ABCDEFGHIJKLMNO", "PQRSTUVWXYZabcd", "efghijklmnopqrs", "tuvwxyz--------" }

  92. 26

    16

    Returns: {"ABCDEFGHIJKLMNOP", "QRSTUVWXYZabcdef", "ghijklmnopqrstuv", "wxyz------------" }

  93. 26

    17

    Returns: {"ABCDEFGHIJKLMNOPQ", "RSTUVWXYZabcdefgh", "ijklmnopqrstuvwxy", "z----------------" }

  94. 26

    18

    Returns: {"ABCDEFGHIJKLMNOPQR", "STUVWXYZabcdefghij", "klmnopqrstuvwxyz--" }

  95. 26

    19

    Returns: {"ABCDEFGHIJKLMNOPQRS", "TUVWXYZabcdefghijkl", "mnopqrstuvwxyz-----" }

  96. 26

    20

    Returns: {"ABCDEFGHIJKLMNOPQRST", "UVWXYZabcdefghijklmn", "opqrstuvwxyz--------" }

  97. 26

    21

    Returns: {"ABCDEFGHIJKLMNOPQRSTU", "VWXYZabcdefghijklmnop", "qrstuvwxyz-----------" }

  98. 26

    22

    Returns: {"ABCDEFGHIJKLMNOPQRSTUV", "WXYZabcdefghijklmnopqr", "stuvwxyz--------------" }

  99. 26

    23

    Returns: {"ABCDEFGHIJKLMNOPQRSTUVW", "XYZabcdefghijklmnopqrst", "uvwxyz-----------------" }

  100. 26

    24

    Returns: {"ABCDEFGHIJKLMNOPQRSTUVWX", "YZabcdefghijklmnopqrstuv", "wxyz--------------------" }

  101. 26

    25

    Returns: {"ABCDEFGHIJKLMNOPQRSTUVWXY", "Zabcdefghijklmnopqrstuvwx", "yz-----------------------" }

  102. 1

    2

    Returns: {"A-", "a-" }

  103. 5

    10

    Returns: {"ABCDE-----", "abcde-----" }

  104. 1

    10

    Returns: {"A---------", "a---------" }


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: