Find the enclosing rectangle for the area. Calculate minX, maxX, minY, maxY.
Now find whether the enclosing area lies to left and right side of the
path**. Note that the path is not self-intersecting.
currX = startX;
area = 0
if ( left ) // enclosing area to left of path
{
for each move
{
if ( north ) increment currX;
if ( south ) decrement currX;
if ( east ) area -= ( currX - minX ) * blocks
if ( west ) area += ( currX - minX ) * blocks
}
}
else // enclosing are to right of path
{
for each move
{
if ( north ) increment currX;
if ( south ) decrement currX;
if ( east ) area += ( currX - minX ) * blocks
if ( west ) area -= ( currX - minX ) * blocks
}
}
** I am not sure how to determine on which side of the path the enclosing
area lies. Probably, if number of right turns > number of left turns, then
it lies on the right side. This seems naive, maybe incorrect, I am not too
sure about it. Can anyone comment?
~Vishal
On 10/5/07, adak <[EMAIL PROTECTED]> wrote:
>
>
> For each test case
> Do
> call function Read_it() /* read the next move */
> call Count_it() /* count the # of squares walked
> through */
> while (move length is > 0)
>
> print area moved through for that case
>
> next
>
> That would be my starting pseudo-code.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---