Number of consecutive balls

Source: Internet
Author: User

Intfree () 18:49:59 on the topic Development/technology/project/Data Structure and algorithm questions

Questions about a middle school competition:

There are L balls, 1 .. l numbers. Two people take the ball in turn.
Each time, each person can (required) Obtain "sequential" A, B, or C balls.
Until it cannot be obtained, the final player wins

Give A, B, C, L, and ask whether the first accessor has a winning strategy

Where 1 <= A, B, C <= L <= 500,
A, B, and C are both even and L is odd, or A, B, and C are odd and L is even

Some of my conclusions:
If a = B = C, then
A <= L <3a-1, wins first
L = 3a-1, win
3A <= L <5a-1, wins first
L = 5a-1
5A <= L <9a-3, win first
When l = 9a-3, the final winner

L I don't know what to do. If A, B, and C are not equal, I don't know how to do it.

One of my colleagues said that the correct algorithm can be parsed within 64 KB of memory within 1 s, but I cannot think of it.

Please help.


Mathe () replied to 09:17:09 score 0
// I have solved the problem now, the speed is very quick.

# Define M 512

Assert (L <m );
Assert (a> 0 & B> 0 & C> 0 );

Int M [m];
For (I = 0; I <= L; I ++ ){
Int N [m];
Memset (n, 0, sizeof (n ));
If (I-A> = 0 ){
For (j = 0; j <= (I-A)/2; j ++) N [M [J] ^ m [(I-a-j)] = 1;
}
If (I-B> = 0 ){
For (j = 0; j <= (I-B)/2; j ++) N [M [J] ^ m [(I-B-j)] = 1;
}
If (I-c> = 0 ){
For (j = 0; j <= (I-c)/2; j ++) N [M [J] ^ m [(I-c-j)] = 1;
}
For (j = 0; j <m; j ++)
If (N [J] = 0) break;
M [I] = J;
}

If (M [l] = 0 ){
Printf ("the first player will lost/N ");
}
Else
{
Printf ("the first player will win/N ");
}
Mathe () replied to 09:39:52 score 15
When the first hand is at M [l] <> 0, the winning strategy is:
After any competitor chooses (or the first time,
The remaining data is continuous data in K groups. The lengths are A (1), a (2),..., A (k ).
Then M [A (1)] ^ m [A (2)] ^... ^ m [A (k)] = u! = 0.
Set the highest bit of u to s, that is, POW (2, s) <= u <POW (2, S + 1 ), there must be I (1 <= I <= k) so that (M [A (I)] & (1 <s ))! = 0, (there is at least one corresponding m, and the second is not 0 .) So M [A (I)]> (M [A (I)] ^ U ).
If the data length of Group I is a (I), we must have a solution to create two new groups in group I.
M [A (I)] ^ U) corresponds to M ). That is, it can be converted
M [A (1)] ^ m [A (2)] ^... ^ m [A (k)] = 0.

We need to prove that for the state 0, the State is not zero after any ball is taken; but for the non-zero state, there can always be a ball fetch solution to restore the State to 0.
The state defined by the above program has the following properties. If status I <status J, there is always a ball fetch scheme, from status J to status I.

From the above nature, I also need to prove an interesting mathematical problem:
If I <> J
Any data smaller than I ^ J appears in the previous collection
{I ^ 0, I ^ 1,..., I ^ (J-1), J ^ 0, J ^ 1,..., J ^ (I-1 )}
Of course, I ^ J does not appear in this collection.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.