Avoid if statements for checking neighboring indexes in a 2D array

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 17 04:43:42 PDT 2017


On Sunday, 16 July 2017 at 21:50:19 UTC, kerdemdemir wrote:

> 			Process(row-1,column-1, maxrow, maxcolumn);
> 			Process(row,column-1, maxrow, maxcolumn);
> 			Process(row+1,column-1, maxrow, maxcolumn);
> 			Process(row-1,column, maxrow, maxcolumn);
> 			Process(row+1,column, maxrow, maxcolumn);
> 			Process(row-1,column+1, maxrow, maxcolumn);
> 			Process(row,column+1, maxrow, maxcolumn);
> 			Process(row-1,column+1, maxrow, maxcolumn);

One of "row-1,column+1" should actually be "row+1,column+1".  
That's where the mentioned ways help.

As for the problem itself, it can be solved without finding 
connected components.  I won't post the solution right away 
because it is potentially a spoiler.  See 
http://codeforces.com/blog/entry/53268 for problem analysis 
(828B) and http://codeforces.com/contest/828/submission/28637184 
for an example implementation in D.

Ivan Kazmenko.



More information about the Digitalmars-d-learn mailing list