rterte's blog

By rterte, history, 6 years ago, In English

I'm having the following problem:

A park that have the form of a m x n board. There are k kinds of trees (1 <= k <= 100). The park is divided into m x n cells and each cell, they'll plant a tree. Now, on the map, each cell of the park have an integer i inside if the i-th kind of tree is planted in it, or a 0 if no tree is planted in it. A line of cells is considered "good" if it has at least t trees of same types, (and they must be on the same either line or column). Count the number of trees that is not in a "good" line.

Input: Integers m, n, t and an m x n array of integers represent the map.

Output: Number of trees that is not in a "good" line.

Example:

Input: 5 6 3

1 3 3 3 3 4

1 2 3 2 0 4

3 2 2 2 4 4

1 0 0 2 4 0

1 2 3 0 4 4

Output: 10

Explanation: The bold numbers are the trees that is not in a good line.

1 3 3 3 3 4

1 2 3 2 0 4

3 2 2 2 4 4

1 0 0 2 4 0

1 2 3 0 4 4

My idea is to check for each element in the array. If it is satisfied then I'll move to the nearest element outside the "good" line. Else, it will just move to the next element on the same line, or if the line is ended then the next element on the column. But it doesn't print any output. Here is my code: https://ideone.com/woMUXd . Can someone please check where did I make a mistake and provide me a direction? Thanks.

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?