HDU 5724 Chess from Meng to learn SG function

Source: Internet
Author: User
introduced the classic Nim game

Give a bunch of stones, Alice and Bob take turns taking stones, each time can choose one of them to take away any number of stones, but not to take. The last person who has no stones to lose.
Known: Heap n, number of stones per heap AI a_i,alice first fetch.
Ask: Who is the winner.

The game is based on the two smart enough, each time to win the status of winning, there is no one of them obviously can win the situation to let others win. So winning and losing is often determined by the situation itself. That is, there is a winning state, must fail.

The above game must be defeated, that is, the player is facing the situation without any stones.

To be able to go through one step of the existence of the state, must be a win state.
After one-step operation is all the state of winning, must be a must-fail state.

can find
A1⨁a2⨁ ... ⨁an=1 a_1 \bigoplus a_2\bigoplus ... \bigoplus a_n=1 for the winning state
A1⨁a2⨁ ... ⨁an=0 a_1 \bigoplus a_2\bigoplus ... \bigoplus a_n=0 is a must-fail Mex function

The MEX operand is a set of S,mex (s), which is the smallest non-negative integer that does not belong to S. Such as

S MEX (S)
Φ\phi 0
{A-i} 0
{0,1,4} 2
definition

For a given direction-free graph, each point on the graph represents a situation or state.
The SG function that defines each vertex of the graph is as follows SG (x) =mex{sg (y) |x→y} SG (x) =mex\{sg (y) | X\rightarrow y\}

When ∃y,sg (y) = 0, then SG (x) ≠0 when \exists y, sg (y) = 0, then SG (x) \ne 0
When ∀y,sg (y) ≠0, then SG (x) =0 when \forall y, sg (y) \ne 0, then SG (x) =0

This description is exactly the same as that of the above, and it can be seen that when SG (x) =0 sg (x) =0, X is a must-fail state.

If there are a number of parallel situations together to form a game, then the status of the parent situation of the SG value of the sub-situation determines
SG (A1) ⨁SG (A2) ⨁ ... ⨁SG (AN) =0 is a must-fail SG (a_1) \bigoplus sg (a_2) \bigoplus ... \bigoplus sg (a_n) =0 is a must-fail state

Application

Finally to do the problem. HDU 5724 Chess

This year's first multi-school, the results of three people did not see the problem (the number of the second more than the appearance of t.t)

Test instructions: nx20 The chess board placed some pieces, each piece to the right of the nearest space for a operation, Alice and Bob take turns to play chess, no way to lose. Alice is the initiator. Ask if Alice will lose.

Each row is independent, so long as the value of the SG function is calculated for each line of state, the answer is obtained by XOR.
If there are x pieces in a row, then it can reach the state y is x, through the SG (x) =mex{

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.