|
| 1 | +# TeamPizza |
| 2 | +Google hashcode task |
| 3 | +Pizza |
| 4 | +Practice Problem for Hash Code 2017 |
| 5 | +Introduction |
| 6 | +Did you know that at any given time, someone is cutting pizza somewhere around the world? The decision |
| 7 | +about how to cut the pizza sometimes is easy, but sometimes it’s really hard: you want just the right amount |
| 8 | +of tomatoes and mushrooms on each slice. If only there was a way to solve this problem using technology... |
| 9 | +Problem description |
| 10 | +Pizza |
| 11 | +The pizza is represented as a rectangular, 2-dimensional grid of R rows and C columns. The cells within the |
| 12 | +grid are referenced using a pair of 0-based coordinates [r, c] , denoting respectively the row and the |
| 13 | +column of the cell. |
| 14 | +Each cell of the pizza contains either: |
| 15 | +● mushroom, represented in the input file as M ; or |
| 16 | +● tomato, represented in the input file as T |
| 17 | +Slice |
| 18 | +A slice of pizza is a rectangular section of the pizza delimited by two rows and two columns, without holes. |
| 19 | +The slices we want to cut out must contain at least L cells of each ingredient (that is, at least L cells of |
| 20 | +mushroom and at least L cells of tomato) and at most H cells of any kind in total - surprising as it is, there is |
| 21 | +such a thing as too much pizza in one slice. |
| 22 | +The slices being cut out cannot overlap. The slices being cut do not need to cover the entire pizza. |
| 23 | +Goal |
| 24 | +The goal is to cut correct slices out of the pizza maximizing the total number of cells in all slices. |
| 25 | +Input data set |
| 26 | +The input data is provided as a data set file - a plain text file containing exclusively ASCII characters with |
| 27 | +lines terminated with a single ‘\n’ character at the end of each line (UNIX- style line endings). |
| 28 | +File format |
| 29 | +The file consists of: |
| 30 | +● one line containing the following natural numbers separated by single spaces: |
| 31 | +○ R (1 ≤ R ≤ 1000) is the number of rows, |
| 32 | +○ C (1 ≤ C ≤ 1000) is the number of columns, |
| 33 | +○ L (1 ≤ L ≤ 1000) is the minimum number of each ingredient cells in a slice, |
| 34 | +○ H (1 ≤ H ≤ 1000) is the maximum total number of cells of a slice |
| 35 | +© Google 2017, All rights reserved. |
| 36 | +● R lines describing the rows of the pizza (one after another). Each of these lines contains C |
| 37 | +characters describing the ingredients in the cells of the row (one cell after another). Each character |
| 38 | +is either ‘M’ (for mushroom) or ‘T’ (for tomato). |
| 39 | +Example |
| 40 | +3 5 1 6 |
| 41 | +TTTTT |
| 42 | +TMMMT |
| 43 | +TTTTT |
| 44 | +3 rows, 5 columns, min 1 of each ingredient per slice, max 6 cells per slice |
| 45 | +Example input file. |
| 46 | +Submissions |
| 47 | +File format |
| 48 | +The file must consist of: |
| 49 | +● one line containing a single natural number S (0 ≤ S ≤ R × C) , representing the total number of |
| 50 | +slices to be cut, |
| 51 | +● U lines describing the slices. Each of these lines must contain the following natural numbers |
| 52 | +separated by single spaces: |
| 53 | +○ r 1 , c 1 , r 2 , c 2 describe a slice of pizza delimited by the rows r (0 ≤ r1 |
| 54 | +,r2 < R, 0 ≤ c1 |
| 55 | +, c2 < C) 1 and |
| 56 | +r 2 and the columns c 1 and c 2 , including the cells of the delimiting rows and columns. The |
| 57 | +rows ( r 1 and r 2 ) can be given in any order. The columns ( c 1 and c 2 ) can be given in any order |
| 58 | +too. |
| 59 | +Example |
| 60 | +3 |
| 61 | +0 0 2 1 |
| 62 | +0 2 2 2 |
| 63 | +0 3 2 4 |
| 64 | +3 slices. |
| 65 | +First slice between rows (0,2) and columns (0,1). |
| 66 | +Second slice between rows (0,2) and columns (2,2). |
| 67 | +Third slice between rows (0,2) and columns (3,4). |
| 68 | +Example submission file. |
| 69 | +© Google 2017, All rights reserved. |
| 70 | +Slices described in the example submission file marked in green, orange and purple. |
| 71 | +Validation |
| 72 | +For the solution to be accepted: |
| 73 | +● the format of the file must match the description above, |
| 74 | +● each cell of the pizza must be included in at most one slice, |
| 75 | +● each slice must contain at least L cells of mushroom, |
| 76 | +● each slice must contain at least L cells of tomato, |
| 77 | +● total area of each slice must be at most H |
| 78 | +Scoring |
| 79 | +The submission gets a score equal to the total number of cells in all slices. |
| 80 | +Note that there are multiple data sets representing separate instances of the problem. The final |
| 81 | +score for your team is the sum of your best scores on the individual data sets. |
| 82 | +Scoring example |
| 83 | +The example submission file given above cuts the slices of 6, 3 and 6 cells, earning 6 + 3 + 6 = 15 points. |
0 commit comments