|
|
вернуться в форумHint! I've solved this problem using this logic. 1. Definitions. integer GetLineNumber(x) - returns a line number of the 'x' element in the triangle. boolean IsTop(x, linex) - returns TRUE, if the 'x' element, which is situated on 'linex' line, has a common edge with a neighbour from 'linex - 1' line. [define IsTop(1, 1) = FALSE] integer RightMove(x) begin if (IsTop(x, GetLineNumber(x)) x = x + 1; return (x + 2 * GetLineNumber(x)); end; integer LeftMove(x) begin if (IsTop(x, GetLineNumber(x)) x = x - 1; return (x + 2 * GetLineNumber(x)); end; 2. Statement. a) 'm' and 'n' ('n' > 'm') are situated on the lines 'linem' and 'linen'. b) rightp = RightMove(RightMove(...RightMove(m)...)) [('linen' - 'linem') times repeated]. leftp = LeftMove(LeftMove(...LeftMove(m)...)) [('linen' - 'linem') times repeated]. c) If 'leftp' <= 'n' <= 'rightp' than the length of the path from 'm' to 'n' is equal to the length of the path from 'm' to any 'p' such, that 'leftp' <= 'p' <= 'rightp'. All you need is to add some code which will count the edges while using RightMove and LeftMove functions and understand, what to do, if the condition 'leftp' <= 'n' <= 'rightp' is FALSE. |
|
|