10940 - Throwing cards away II
Moderator: Board moderators
10940 - Throwing cards away II
my method is
if n ==6
then
1. 1 2 3 4 5 6
( n=6=even , so copy ar[1]..ar[3] to ar[0].., then n/=2 )
2. 2 4 6
( n==3==odd , so copy ar[end] to ar[0] , then copy ar[1]..a[3]....to ar[
1]... )
3 6 4
4 4
but it is too slow
can someone give me some hint , thanks
if n ==6
then
1. 1 2 3 4 5 6
( n=6=even , so copy ar[1]..ar[3] to ar[0].., then n/=2 )
2. 2 4 6
( n==3==odd , so copy ar[end] to ar[0] , then copy ar[1]..a[3]....to ar[
1]... )
3 6 4
4 4
but it is too slow
can someone give me some hint , thanks
studying @ ntu csie
It's exactly the Josephus Problem. It's quite well known in the programing contest community.
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
10940 - Throwing cards away II
got accepted
Last edited by asif_rahman0 on Sun Oct 23, 2005 9:58 pm, edited 1 time in total.
-
- Learning poster
- Posts: 70
- Joined: Sat Feb 05, 2005 9:38 am
- Location: Gurukul
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
hi Raj_ariyan u r right.
i also know that.
but i always try something different.ok
first time i was bit complex with my code...but after ur wrote i thought
another different way... & finaly i got accepted(0.56sec).
may be its too much but i think its creative:)
am i right ????
my algo is:
1) find power of 2^(0<i<20)that is smaller than the given number
2) then calculate power of 2^(i-1)
3) then minus this number from given value (eg. n=19 value=19-16=3
so 3*2=6 result is 6)
![:)](./images/smilies/icon_smile.gif)
but i always try something different.ok
first time i was bit complex with my code...but after ur wrote i thought
another different way... & finaly i got accepted(0.56sec).
may be its too much but i think its creative:)
am i right ????
my algo is:
1) find power of 2^(0<i<20)that is smaller than the given number
2) then calculate power of 2^(i-1)
3) then minus this number from given value (eg. n=19 value=19-16=3
so 3*2=6 result is 6)
-
- Experienced poster
- Posts: 131
- Joined: Sat Jul 17, 2004 4:09 am
- Location: Lima, Per
-
- Experienced poster
- Posts: 131
- Joined: Sat Jul 17, 2004 4:09 am
- Location: Lima, Per
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
Just solve
Hi solvers I've just solve this problem....
I found a sequence...
from starting at n=2
2,2,4,2,4,8,10,12,14,16,2,4,8,10,12,14,16,18,20,22,24,26,28,30,32,2,4,...........
And only exception if n=1..
answer=1...
It seems very interesting to me....
Why it works(accepted)....
would anyone make answer this through mathmatical prove...
I'm curiously waiting...
...Tanu
I found a sequence...
from starting at n=2
2,2,4,2,4,8,10,12,14,16,2,4,8,10,12,14,16,18,20,22,24,26,28,30,32,2,4,...........
And only exception if n=1..
answer=1...
It seems very interesting to me....
Why it works(accepted)....
would anyone make answer this through mathmatical prove...
I'm curiously waiting...
...Tanu
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: Just solve
Actually it is: (1,)2,2,4,2,4,6,8,2,4,6,8,10,12,14,16,2,4,6,8,10,12,14,16,18,20,22,24,26,28,...Tanu wrote:Hi solvers I've just solve this problem....
I found a sequence...
from starting at n=2
2,2,4,2,4,8,10,12,14,16,2,4,8,10,12,14,16,18,20,22,24,26,28,30,32,2,4,...........
And only exception if n=1..
answer=1...
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: Just solve
Maybe you can get it from these recurences:Tanu wrote:It seems very interesting to me....
Why it works(accepted)....
would anyone make answer this through mathmatical prove...
I'm curiously waiting...
...Tanu
Code: Select all
f(1)=1
f(2*k)=2*f(k)
f(2*k+1)=2*g(k)
g(1)=1
g(2*k)=2*g(k)-1
g(2*k+1)=2*f(k+1)-1