[algogeeks] Re: Programing problem

2007-10-07 Thread macharla pradeep
Hi,
if  ( commnad sequence is bad )
whether to include it area calculation or not??


On 10/5/07, piruk [EMAIL PROTECTED] wrote:


 Hi.
   How to solve this task?


 Areameter is a turtle-like self-propelled vehicle controlled by
 sequences of commands transmitted over a radio channel. Initially the
 vehicle is oriented in some fixed direction, let's say to the North.
 Commands instruct Areameter how far to move in the current direction
 and where to turn after the move. Allowed turns are +90 or -90 degrees
 relative to the current direction. By positive turn we mean turning to
 the right (clockwise).

 A command sequence is good if it brings the vehicle to the starting
 point and starting orientation after tracing a closed non self-
 intersecting path. On coming back to the starting point Areameter
 should emits the area (number of square units) of the territory walked
 around.

 Write a program to perform Areameter's task of calculating the area
 from the sequence of received commands.

 Input

 The standard input stream contains a sequence of test cases specified
 as follows:

 The first line contains a positive integer n, number of test cases.
 A test case is simply one good command sequence spread over one or
 more lines. Each command sequence consists of alternating move and
 turn commands. Move command is represented by a positive integer; turn
 command is represented by single character '+' or '-'. End of command
 sequence is coded by giving 0 for move command. Commands are separated
 by at least one white-space character. You can assume the input is
 well-formed and contains only good command sequences. There are no a
 priori constraints on the sequence length. The values of moves and the
 resulting area are all within integer representation.

 Output

 For each test case the program should output one text line containing
 a number: the area in square units.

 Example
 Input
 3
 3 + 3 + 3 + 3 + 0

 2 + 2 + 3 - 3 - 1 + 2 + 3 + 3 +
 1 - 3 + 2 - 1 + 0

 2 + 2 - 1 - 1 + 1 + 3 + 3 + 2 - 2 -
 4 - 4 + 2 + 2 + 1 - 1 - 2 +
 1 + 1 - 1 + 7 + 2 - 1 + 0

 Output
 9
 16
 27


 



-- 
PRADEEP MACHARLA
Ph:08040141194

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Programing problem

2007-10-07 Thread Ajinkya Kale
On 10/7/07, macharla pradeep [EMAIL PROTECTED] wrote:

 Hi,
 if  ( commnad sequence is bad )
 whether to include it area calculation or not??


It is mentioned that command sequence is never bad.


  On 10/5/07, piruk [EMAIL PROTECTED] wrote:
 
 
  Hi.
How to solve this task?
 
 
  Areameter is a turtle-like self-propelled vehicle controlled by
  sequences of commands transmitted over a radio channel. Initially the
  vehicle is oriented in some fixed direction, let's say to the North.
  Commands instruct Areameter how far to move in the current direction
  and where to turn after the move. Allowed turns are +90 or -90 degrees
  relative to the current direction. By positive turn we mean turning to
  the right (clockwise).
 
  A command sequence is good if it brings the vehicle to the starting
  point and starting orientation after tracing a closed non self-
  intersecting path. On coming back to the starting point Areameter
  should emits the area (number of square units) of the territory walked
  around.
 
  Write a program to perform Areameter's task of calculating the area
  from the sequence of received commands.
 
  Input
 
  The standard input stream contains a sequence of test cases specified
  as follows:
 
  The first line contains a positive integer n, number of test cases.
  A test case is simply one good command sequence spread over one or
  more lines. Each command sequence consists of alternating move and
  turn commands. Move command is represented by a positive integer; turn
  command is represented by single character '+' or '-'. End of command
  sequence is coded by giving 0 for move command. Commands are separated
  by at least one white-space character. You can assume the input is
  well-formed and contains only good command sequences. There are no a
  priori constraints on the sequence length. The values of moves and the
  resulting area are all within integer representation.
 
  Output
 
  For each test case the program should output one text line containing
  a number: the area in square units.
 
  Example
  Input
  3
  3 + 3 + 3 + 3 + 0
 
  2 + 2 + 3 - 3 - 1 + 2 + 3 + 3 +
  1 - 3 + 2 - 1 + 0
 
  2 + 2 - 1 - 1 + 1 + 3 + 3 + 2 - 2 -
  4 - 4 + 2 + 2 + 1 - 1 - 2 +
  1 + 1 - 1 + 7 + 2 - 1 + 0
 
  Output
  9
  16
  27
 
 
 
 
 


 --
 PRADEEP MACHARLA
 Ph:08040141194
 



-- 
Ciao,
Ajinkya

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Programing problem

2007-10-05 Thread adak

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 algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] Re: Programing problem

2007-10-05 Thread Vishal
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 algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---