Thread: Neigbour array elements

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    5

    Neigbour array elements

    I'm dealing with 2 dimensional arrays and i couldn't figure out how to do this:

    for example assume we have a 4x4 matrix, and there is a predefined number k(which is between 0 and 128).well let's declare the array as a[i][j]. for example if the value of a[i][j]>k and if the neigbours of a[i][j]<=k,it will count 1.
    but when a[i][j]>k , if one or more of a[i][j]'s neigbours is also bigger than k ,it will also count 1. I mean,for example if a[0][0]>k,a[0][1]>k and a[1][1]>k this whole 3 cell count as 1.
    how can i make this?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by ashley90 View Post
    I mean,for example if a[0][0]>k,a[0][1]>k and a[1][1]>k...
    Not sure about your requirements and by chance did you mean
    Code:
    a[0][0]>k, a[0][1]>k and a[1][0]>k
    Since a[1][0] comes before a[1][1] in relation to a[0][0].

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    |0 |0 |0 |1 |0 |1 |
    |0 |1 |1 |1 |1 |0 |
    |0 |0 |1 |0 |0 |0 |
    |0 |0 |1 |1 |0 |0 |
    |0 |0 |0 |0 |0 |0 |

    for example in here the count will be 2. a[0][5] counts 1 because it has no neigbors with 1( bigger than k)(diagonal not counts). but from a[0][3] to other 1's below it, there is a path without entering a 0 cell. So all of it counts 1. and totally count=2.

    well i couldn't figure out how to find that kind of paths.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Okay so I am confused about your requirements. State them as simply and clearly as possible and more than likely someone from the cboard will help out.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    Quote Originally Posted by itCbitC View Post
    Okay so I am confused about your requirements. State them as simply and clearly as possible and more than likely someone from the cboard will help out.
    Look, for example consider this 2x2 matrix:

    when

    1 0
    0 1 in here count=2 because we can't find a path between cell of 1's without entering a cell of 0

    1 1
    0 0 but in here count=1 because there is path between 1's without entering 0 cell and it counts 1

    it's obvious i guess. the same thing goes for the above matrix i gave.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by ashley90 View Post
    Look, for example consider this 2x2 matrix:

    when

    1 0
    0 1 in here count=2 because we can't find a path between cell of 1's without entering a cell of 0

    1 1
    0 0 but in here count=1 because there is path between 1's without entering 0 cell and it counts 1

    it's obvious i guess. the same thing goes for the above matrix i gave.
    In the
    1 0
    0 1 matrix, the count is 2 because you have two 1's that have no path to other cells, right?

    And in this matrix:
    1 1
    0 0
    the count is 1 because it has no path to the last row.

    If the matrix were:
    1 1
    0 0
    0 0
    then would the count be 2 (meaning we're counting the number of rows with no path to them), or would it be one, because we're counting the link(s) between two cells.

    What would these counts be?
    1 1
    0 1
    0 1

    1 1
    0 0
    1 1

    As we loop (iterate) through the loop, what *exactly* triggers a count increase? That's all we need to know. Your prior description was more of a pronouncement. "Count is N!"

    If you can "nail down" the description, of just exactly what we're counting, the problem will be solved in a jiffy. Then it's a trivial problem to code up.

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    I probably won't be one of the ones helping with code, but...

    EDIT: Oh, never mind that post if you read it. You're counting the number of "continents," or contiguous blocks of cells >k, in the matrix.
    Last edited by Jesdisciple; 04-12-2009 at 08:13 PM.

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Do it out on paper. How would you count continents without the computer. Then, translate the algorithim you come up with into C.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    Quote Originally Posted by King Mir View Post
    Do it out on paper. How would you count continents without the computer. Then, translate the algorithim you come up with into C.
    Yeah i did it on paper but couldn't convert it to a code. For example i wrote first a function which gives 1 or 0 to cell according to their value and k. Then i tried to check every cell one by one. If it has no neigbor with 1's , its easy to convert to code but i couldn't do the second part which if a cell has a neigbor with 1 and also if this neigbor cell of 1 has neigbors with 1...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding More Array Elements?
    By Vermillion in forum C++ Programming
    Replies: 2
    Last Post: 09-14-2008, 10:02 PM
  2. coping elements not in array
    By lord in forum C++ Programming
    Replies: 2
    Last Post: 08-04-2008, 07:53 PM
  3. way to check 3 elements of array and set 4th
    By Syneris in forum C++ Programming
    Replies: 3
    Last Post: 01-09-2006, 11:30 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. A simple question about selecting elements in an array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 10:37 PM