TopCoder problem "Surveyor" used in TCCC '04 Qual. 1 (Division I Level Two)



Problem Statement

    *** You may only submit a given problem once - no resubmissions will be accepted. ***



A plot has been surveyed. Its boundary consists of segments that form a polygon. Each segment runs either North-South or East-West. Create a class Surveyor that contains a method area that takes as input a String direction and a int[] length and returns the enclosed area.

The i-th character of direction and the i-th element of length describe the direction and length of the i-th segment of the polygon's boundary as the surveyor walked it. If you start at the surveyor's starting point and walk according to the sequence of directions and lengths reported by the surveyor, you will traverse the boundary of the polygon, ending up back at the starting point. This traversal described by the given segments may be either clockwise or counterclockwise.

 

Definition

    
Class:Surveyor
Method:area
Parameters:String, int[]
Returns:int
Method signature:int area(String direction, int[] length)
(be sure your method is public)
    
 

Constraints

-direction will have between 4 and 50 characters inclusive.
-length will have the same number of elements as the number of characters in direction.
-Each element of direction will be an uppercase letter 'N', 'E', 'S', or 'W'.
-Each element of length will be between 1 and 1000 inclusive.
-The segments will represent a simple polygon. No two segments will touch or intersect (except that the last point of a segment is the first point of the next segment, and the last point of the final segment is the first point of the first segment).
 

Examples

0)
    
"NWWSE"
{10,3,7,10,10}
Returns: 100
This plot is a 10 x 10 square.
1)
    
"NESWNWSW"
{20,200,30,100,20,30,10,70}
Returns: 4700
      ___________________
     |       __          |
     |______|  |         |
    S          |_________|
   
The S indicates the Start/End point of the traversal.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1359

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=5000&pm=1359

Writer:

dgoodman

Testers:

lbackstrom , schveiguy

Problem categories:

Geometry