Google中国编程挑战赛第一轮Room18第二题

Problem Statement

    

A group of vertical blocks are placed densely one after another on the ground. The blocks each have a width of 1, but their heights may vary. For example, if the heights of the vertical blocks are given as {1,5,5,1,6,1}, the configuration would look like the following picture:

Your task is to reproduce the exact shape of this structure using some number of non-intersecting rectangles. You will be given a vector <int> heights representing the heights of the vertical blocks from left to right. Return the minimal number of rectangles necessary to perform this task with the given configuration of blocks.

Definition

    
Class: BlockStructure
Method: cover
Parameters: vector <int>
Returns: int
Method signature: int cover(vector <int> heights)
(be sure your method is public)
    

Constraints

- heights will have between 1 and 50 elements, inclusive.
- Each element of heights will be between 1 and 1000, inclusive.

Examples

0)
    
{1,5,5,1,6,1}
Returns: 3

We can use rectangles with sizes 6x1, 2x4 and 1x5.

1)
    
{2,2,2,4,4}
Returns: 2

We can use a 3x2 rectangle and a 2x4 rectangle.

2)
    
{6,6,6,6,6,6}
Returns: 1
The structure is a rectangle.
3)
    
{71,44,95,16,10,80,12,17,98,61}
Returns: 10
It's impossible to use less than 10 rectangles.
4)
    
{100,100,97,100,100,100,97,98,99,99}
Returns: 5

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)2003, TopCoder, Inc. All rights reserved.

google中国编程挑战赛-练习题之二(500分题)

12-08

继续是E文~哭~~rnrnProblem Statementrn rnA square matrix is a grid of NxN numbers. For example, the following is a 3x3 matrix:rn 4 3 5rn 2 4 5rn 0 1 9rnOne way to represent a matrix of numbers, each of which is between 0 and 9 inclusive, is as a row-major String. To generate the String, simply concatenate all of the elements from the first row followed by the second row and so on, without any spaces. For example, the above matrix would be represented as "435245019". You will be given a square matrix as a row-major String. Your task is to convert it into a String[], where each element represents one row of the original matrix. Element i of the String[] represents row i of the matrix. You should not include any spaces in your return. Hence, for the above String, you would return "435","245","019". If the input does not represent a square matrix because the number of characters is not a perfect square, return an empty String[], .rnDefinitionrn rnClass:rnMatrixToolrnMethod:rnconvertrnParameters:rnStringrnReturns:rnString[]rnMethod signature:rnString[] convert(String s)rn(be sure your method is public)rn rnrnConstraintsrn-rns will contain between 1 and 50 digits, inclusive.rnExamplesrn0)rnrn rn"435245019"rnReturns: "435", "245", "019" rnThe example above.rn1)rnrn rn"9"rnReturns: "9" rnrn2)rnrn rn"0123456789"rnReturns: rnThis input has 10 digits, and 10 is not a perfect square.rn3)rnrn rn"3357002966366183191503444273807479559869883303524"rnReturns: "3357002", "9663661", "8319150", "3444273", "8074795", "5986988", "3303524" rnrnThis 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)2003, TopCoder, Inc. All rights reserved.

google中国编程挑战赛-练习题之三(250分题)

12-08

哎,看来我得先去学几年E再说了~TTrnrnrnProblem Statementrn rnA simple line drawing program uses a blank 20 x 20 pixel canvas and a directional cursor that starts at the upper left corner pointing straight down. The upper left corner of the canvas is at (0, 0) and the lower right corner is at (19, 19). You are given a String[], commands, each element of which contains one of two possible commands. A command of the form "FORWARD x" means that the cursor should move forward by x pixels. Each pixel on its path, including the start and end points, is painted black. The only other command is "LEFT", which means that the cursor should change its direction by 90 degrees counterclockwise. So, if the cursor is initially pointing straight down and it receives a single "LEFT" command, it will end up pointing straight to the right. Execute all the commands in order and return the resulting 20 x 20 pixel canvas as a String[] where character j of element i represents the pixel at (i, j). Black pixels should be represented as uppercase 'X' characters and blank pixels should be represented as '.' characters.rnDefinitionrn rnClass:rnDrawLinesrnMethod:rnexecuternParameters:rnString[]rnReturns:rnString[]rnMethod signature:rnString[] execute(String[] commands)rn(be sure your method is public)rn rnrnNotesrn-rnThe cursor only paints the canvas if it moves (see example 1).rnConstraintsrn-rncommands will contain between 1 and 50 elements, inclusive.rn-rnEach element of commands will be formatted as either "LEFT" or "FORWARD x" (quotes for clarity only), where x is an integer between 1 and 19, inclusive, with no extra leading zeros.rn-rnWhen executing the commands in order, the cursor will never leave the 20 x 20 pixel canvas.rnExamplesrn0)rnrn rn"FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19"rnReturns: rn"XXXXXXXXXXXXXXXXXXXX",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "X..................X",rn "XXXXXXXXXXXXXXXXXXXX" rnThis sequence of commands draws a 20 x 20 outline of a square. The cursor is initially at (0, 0) pointing straight down. It then travels to (0, 19) after the first FORWARD command, painting each pixel along its path with a '*'. It then rotates 90 degrees left, travels to (19, 19), rotates 90 degrees left, travels to (19, 0), rotates 90 degrees left, and finally travels back to (0, 0).rn1)rnrn rn"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"rnReturns: rn"....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "...................." rnThe cursor spins round and round, but never actually paints any pixels. The result is an empty canvas.rn2)rnrn rn"FORWARD 1"rnReturns: rn"X...................",rn "X...................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "....................",rn "...................." rnGoing forward by one pixel creates a line that is 2 pixels long because both the start and end points are painted.rn3)rnrn rn"LEFT", "FORWARD 19", "LEFT", "LEFT", "LEFT",rn "FORWARD 18", "LEFT", "LEFT", "LEFT", "FORWARD 17",rn "LEFT", "LEFT", "LEFT", "FORWARD 16", "LEFT",rn "LEFT", "LEFT", "FORWARD 15", "LEFT", "LEFT", "LEFT",rn "FORWARD 14", "LEFT", "LEFT", "LEFT", "FORWARD 13",rn "LEFT", "LEFT", "LEFT", "FORWARD 12", "LEFT", "LEFT",rn "LEFT", "FORWARD 11", "LEFT", "LEFT", "LEFT", "FORWARD 10",rn "LEFT", "LEFT", "LEFT", "FORWARD 9", "LEFT", "LEFT",rn "LEFT", "FORWARD 8", "LEFT", "LEFT", "LEFT", "FORWARD 7"rnReturns: rn"XXXXXXXXXXXXXXXXXXXX",rn "...................X",rn "..XXXXXXXXXXXXXXXX.X",rn "..X..............X.X",rn "..X.XXXXXXXXXXXX.X.X",rn "..X.X..........X.X.X",rn "..X.X.XXXXXXXX.X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.X........X.X.X",rn "..X.X.XXXXXXXXXX.X.X",rn "..X.X............X.X",rn "..X.XXXXXXXXXXXXXX.X",rn "..X................X",rn "..XXXXXXXXXXXXXXXXXX",rn "...................." rnrnThis 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)2003, TopCoder, Inc. All rights reserved.

google中国编程挑战赛-练习题之一(1000分题)

12-08

全英文滴~看不太懂啊~~~~55555555555555rnrnProblem Statementrn rnWhen editing a single line of text, there are four keys that can be used to move the cursor: end, home, left-arrow and right-arrow. As you would expect, left-arrow and right-arrow move the cursor one character left or one character right, unless the cursor is at the beginning of the line or the end of the line, respectively, in which case the keystrokes do nothing (the cursor does not wrap to the previous or next line). The home key moves the cursor to the beginning of the line, and the end key moves the cursor to the end of the line. You will be given a int, N, representing the number of character in a line of text. The cursor is always between two adjacent characters, at the beginning of the line, or at the end of the line. It starts before the first character, at position 0. The position after the last character on the line is position N. You should simulate a series of keystrokes and return the final position of the cursor. You will be given a string where characters of the string represent the keystrokes made, in order. 'L' and 'R' represent left and right, while 'H' and 'E' represent home and end.rnrnDefinitionrn rnClass:rnCursorPositionrnMethod:rngetPositionrnParameters:rnstring, intrnReturns:rnintrnMethod signature:rnint getPosition(string keystrokes, int N)rn(be sure your method is public)rn rnrnConstraintsrn-rnkeystrokes will be contain between 1 and 50 'L', 'R', 'H', and 'E' characters, inclusive.rn-rnN will be between 1 and 100, inclusive.rnrnExamplesrn0)rnrn rn"ERLLL"rn10rnReturns: 7rnFirst, we go to the end of the line at position 10. Then, the right-arrow does nothing because we are already at the end of the line. Finally, three left-arrows brings us to position 7.rn1)rnrn rn"EHHEEHLLLLRRRRRR"rn2rnReturns: 2rnAll the right-arrows at the end ensure that we end up at the end of the line.rn2)rnrn rn"ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL"rn10rnReturns: 3rnrn3)rnrn rn"RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL"rn19rnReturns: 12rnrnThis 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)2003, TopCoder, Inc. All rights reserved.

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试