Tuesday, August 14, 2012

UVa Online Judge - 11110 - Equidivisions

Problem Statement:        11110 - Equidivisions

Solutions:

I solve this problem with help of DFS.
At first I stored the problem data in a 2-Dimension array, that represents N*N table. In this table I showed each partition with a number from 0 to N-1.
I used an array with the name "mark" that marks each partition when it checked and for mark each cell of table, I used -1 for that cell.
Then I started to move on the table cells.
If a cell isn't equal to -1 it means it didn't check yet. So It can be a partition that didn't check. But if we marked that partition in the mark array before, means that we checked that partition and the answer for this problem is "wrong". Else, we should search the neighbors of this cell to finding another cells of this partition and mark them with -1 to don't check them again, and finally mark this partition as visited partition in the mark array.
Eventually, if we couldn't find "wrong", it means that the answer is "good".
Here is my ACCEPTED code for this problem:


No comments:

Post a Comment