Statistics

Problem Statement for "NumberRings"

Problem Statement

PROBLEM STATEMENT: 
An n-by-n matrix can be considered to have (n+1)/2 rings.  Informally the 3
rings of 
a 5-by-5 matrix are			while those of a 6-by-6 matrix are
AAAAA	-where A is the zeroth ring	AAAAAA	-where A is the zeroth ring
ABBBA          B is the first ring	ABBBBA	       B is the first ring
ABCBA	       C is the second ring	ABCCBA	       C is the second ring
ABBBA					ABCCBA
AAAAA					ABBBBA
					AAAAAA

Consider transforming an n by n matrix by rotating each ring either clockwise
or counterclockwise by some number of turns.  For example, if the 0th ring of
matrix A were rotated clockwise by 2, the 1st ring counter-clockwise by 3, and
the 2nd ring clockwise by 1, the resulting matrix would look like:
               0th ring		1-st ring 		2-nd ring	     Final Matrix
   original  clockwise by 2  counter-clockwise by 3    clockwise by 1
   22222	33222								33222
   31103	3   2		   011						30112
 A=30903	2   2		   0 0			    9			20902
   30113	2   3		   110						21103
   22222	22233		 						22233
Write a method which returns the absolute value of the difference between the
sums of the main diagonals of the matrix after it has been transformed by a
specified series of ring transformations.  The main diagonals are the longest
diagonals in the matrix (one goes from top left corner to bottom right corner
and the other goes from the top right corner to the bottom left corner)  For
the example above the method should return 0 because |3+0+9+0+3 - 2+1+9+1+2| =
|15 - 15| = 0

DEFINITION:
Class Name:  NumberRings
Method Name:  rotate
Parameters:  String[] String[]
   Returns:  int
method signature (make sure your method is public) int rotate(String[] matrix,
String[] rotations)

TopCoder will ensure the validity and format of these inputs:
- matrix is a String[] of size n that contains between 1 and 20 elements
inclusive 
- each string in the matrix String[] contains n integers (so that the matrix is
square)separated by one or more spaces
- each integer in the matrix String[] is a number between -100 and 100 inclusive
- each integer in the matrix String[] will not contain any leading zeros.
- rotations is a String[] consisting of between 0 to 50 elements inclusive
- each string in the rotations String[] has the following format: "rAm" where 
r represents the ring number in the n by n matrix and is an integer such that
0<=r<(n+1)/2
A is either the character 'c' or 'C', where 'c' describes a clockwise
rotation and 'C' a counterclockwise rotation, and m represents the length of
the rotation and is an integer such that 0<=m<1000

EXAMPLES:
{"0 1 2","8 4 5","6 7 9"} {"0c2","0C3"} returns 5
O12   0c2  680   0C3  125 
845   =>   741   =>   049     |(1+4+7) - (8+4+5)| = |12 - 17| = 5
679        952        867

{"0 1","2 5"} {"0c1","0C5","0C29","0c1","0c0"} return 2
{"0 1 2","3 4 5","6 7 9"}  {"0c0","1C1","1c1","0c1","0C1"} return 1
{"3"} {"0c0","0C3"} return 0
{"1 -1 2 -2 3 -3","1 3 13 3 1 4","1 3 9 27 81 72","12 2 4 67 3 4","12 2 4 67 3
4","4 12 34 23 3 4"} {"0C3","0c1","1c6","2C34"} return 11

Definition

Class:
NumberRings
Method:
rotate
Parameters:
String[], String[]
Returns:
int
Method signature:
int rotate(String[] param0, String[] param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: