Matematické Fórum

Nevíte-li si rady s jakýmkoliv matematickým problémem, toto místo je pro vás jako dělané.

Nástěnka
22. 8. 2021 (L) Přecházíme zpět na doménu forum.matweb.cz!
04.11.2016 (Jel.) Čtete, prosím, před vložení dotazu, děkuji!
23.10.2013 (Jel.) Zkuste před zadáním dotazu použít některý z online-nástrojů, konzultovat použití můžete v sekci CAS.

Nejste přihlášen(a). Přihlásit

#1 17. 02. 2021 10:48

ExSh00t
Příspěvky: 224
Reputace:   
 

Recursive form problem elimination game

https://leetcode.com/problems/elimination-game/

Let res(n) = [final number from {1, 2, 3, ..., n} starting elimination from left]

1. Perform a left to right elimination round
=> res(n) = [final number from {2, 4, 6, ..., (n-1) or (n-2) whichever is even} starting elimination from right]

2. Extract common factor of 2
=> res(n) = 2 * [final number from [1, 2, 3, ... n/2] starting elimination from right]

3. Reversing both the direction and the sequence doesn't change anything
=> res(n) = 2 * [final number from {n/2, ..., 3, 2, 1} starting elimination from left]

4. Make the sequence align with original definition of res(n).
To convert {n/2, ..., 3, 2, 1} to {1, 2, 3, ..., n/2}, we could do a[i] = n/2 + 1 - a[i] but then result (which is one of these a[i])
also gets changed so we need to convert it back again by doing (n/2 + 1 - result).
=> res(n) = 2 * (n/2 + 1 - [final number from {1, 2, 3, ..., n/2} starting elimination from left])

5. Voila
=> res(n) = 2 * (n/2 + 1 - res(n/2))

V bode 4 som sa zasekol ako prebieha hlavna konverzia na rekurentny vztah. Co presne znamena a[i] = n/2 + 1 - a[i].
Dakujem

Offline

 

#2 17. 02. 2021 19:07

check_drummer
Příspěvky: 5171
Reputace:   106 
 

Re: Recursive form problem elimination game

↑ ExSh00t:
Ahoj, podle mě to znamená přiřaď do proměnné a[i] hodnotu n/2 + 1 - a[i].


"Máte úhel beta." "No to nemám."

Offline

 

#3 09. 12. 2024 08:34 — Editoval markangelo (09. 12. 2024 08:35)

markangelo
Zelenáč
Příspěvky: 1
Škola: AU US
Reputace:   
 

Re: Recursive form problem elimination game

ExSh00t napsal(a):

https://leetcode.com/problems/elimination-game/ rice purity test

Let res(n) = [final number from {1, 2, 3, ..., n} starting elimination from left]

1. Perform a left to right elimination round
=> res(n) = [final number from {2, 4, 6, ..., (n-1) or (n-2) whichever is even} starting elimination from right]

2. Extract common factor of 2
=> res(n) = 2 * [final number from [1, 2, 3, ... n/2] starting elimination from right]

3. Reversing both the direction and the sequence doesn't change anything
=> res(n) = 2 * [final number from {n/2, ..., 3, 2, 1} starting elimination from left]

4. Make the sequence align with original definition of res(n).
To convert {n/2, ..., 3, 2, 1} to {1, 2, 3, ..., n/2}, we could do a[i] = n/2 + 1 - a[i] but then result (which is one of these a[i])
also gets changed so we need to convert it back again by doing (n/2 + 1 - result).
=> res(n) = 2 * (n/2 + 1 - [final number from {1, 2, 3, ..., n/2} starting elimination from left])

5. Voila
=> res(n) = 2 * (n/2 + 1 - res(n/2))

V bode 4 som sa zasekol ako prebieha hlavna konverzia na rekurentny vztah. Co presne znamena a[i] = n/2 + 1 - a[i].
Dakujem

The key steps involve performing a left-to-right elimination, extracting a common factor, and converting the reversed sequence back to the original order using the formula a[i] = n/2 + 1 - a[i]. This leads to the final recursive formula res(n) = 2 * (n/2 + 1 - res(n/2)).

Offline

 

Zápatí

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson