|
|
back to boardShow all messages Hide all messageslet sequence be 1,2,3,...,n I. in each P( l, r ) there will be 1 + r-l+1 times ++ c. II. in each Q( l, n ) = Q( l, l ) there will be 0 time ++ c. III. in each Q( n, r ) = Q( n+1, r ) + P( n, r ). IV. Let F( n ) is the total times of ++ c, so we get F( n ) = F( n-1 ) + n + 1 and F( 1 ) = Q( r, r ) = 0; the sum of ++ c is 3 + 4 +... + n+1 = n*(n-1)/2 + 2*(n-1) = (n-1)*(n+4)/2 = (n*n+3*n-4)/2 Edited by author 24.05.2011 11:12 Edited by author 24.05.2011 11:13 What the fucking analysis do you do? Simply solve the quadratic equation in the IF condition "if(c==(N*N+3*N-4)/2)", and you will see that with any nonnegative value of "c" the program will print out "Beutiful Vasilisa". The variable "c" will be nonnegative in any case, because of the initial value = 0, and increment operator. I guess u read "if(c=(N*N+3*N-4)/2)" instead of "if(c==(N*N+3*N-4)/2)" Я вывел формулу по другому: n*(n+1)/2 - 1 + (n - 1) = n*(n+1)/2 + (n - 2) = (n*n + 3*n - 4) / 2 n*(n+1)/2 - кол-во проверок на возрастание -1 - вычитаем один случай, когда остался один элемент (n - 1) - кол-во проверок на убывание |
|
|