King Richard's Knights

  • + 1 comment

    (Here's a rewording of the problem, hope it helps)
    You're given a square matrix of size N. You're expected to successively rotate a number of submatrixes +90 degrees and report the -possibly new- indices of a number of element values.
    Each submatrix is also square, and is a submatrix of the previously rotated one.
    Elements are valued columnwise starting from 0, indices start from 1.

    Input:
    First input line is N (size of matrix).
    Second input line is S (the number of rotations), followed by S lines of space separated integer triplets (a b d) describing one submatrix, so that (a b) are indices of top-left element and d is the size.
    S+2nd input line is L (the number of elements, indices of which will be reported), followed by L lines of values.

    Output:
    L lines of space separated integer pairs corresponding to indices of the values specified in input.