hdu 6478 tri-color card draw games · Game Nim

answer

Nim game · Baidu Encyclopedia

Nim definitions :

The usual definition of Nim game is this: There are several heap of stones, the number of each pile of stones is limited, the legal move is " to select a bunch of stones and took several pieces (can not fail to take)," if a turn when all of the individual stones heap have been to take the empty, the penalty negative (because he has no legal move at the moment).
This game looks a bit complicated, start with a simple situation began to study it. If your turn, only a pile of stones, so at this time is certainly a winning strategy to get finished all this pile of stones is not a rival to the left, then the opponents lose. If the remaining piles of stones are not equal, a winning strategy is by taking more than two piles of stones pile of stones will become equal, if the opponent in a heap after a number of stars to take, you can heap in another take as many number of stars, until victory . If you are faced with piles of stones equal, then the time you are no winning strategy, but opponents can follow the above strategy to ensure victory. If three piles of stones ...... seems to have been difficult to analyze, it seems we have to use some other nice (the best is stylized) analysis, or that we can develop a best in there algorithm to find a winning strategy when winning strategy.
P-position and the definition of N-position, wherein the representative P Previous, N Representative Next. Intuitively, the last move of people have a winning strategy situation is P-position, is the "flip guaranteed win" or "losing the upper hand," turn to move people who have a winning strategy situation is N -position, that is "guaranteed win the upper hand." More rigorous definitions are: 1 can not make any movement situation (i.e. terminal position) is the P-position; 2 can be moved to the P-position situation is the N-position; 3 all mobile have led N-position of... the situation is the P-position.
According to this definition, if the situation is not possible to reproduce, or a set of positions can be topologically sorted, then each position or P-position or the N-position, and can be calculated by defining.

For the upper hand, the
current situation is the P-position, losing
the current situation is the N-position, win

Conclusion :

Nim for a game situation (a1, a2, ..., an), which is the P-position (losing) if and only if a1 ^ a2 ^ ... ^ an = 0

For G heap is concerned, follows the nim games, direct conclusions apply
for R and B heap heap is concerned, a player must be a holding,

Approach: first determine the situation brought about all heap G, R and B and then look at the number of


Here Insert Picture Description


#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,k;
string s;
int main(){
    ios::sync_with_stdio(0);

    int T;
    cin>>T;
    for (int cs = 1; cs <= T; ++cs) {

        cin>>n;
        int r=0,g=0,b=0;
        for (int i = 1,x; i <= n; ++i) {
            cin>>s>>x;
            if(s=="R")r+=x;
            else if(s=="G")g^=x;
            else b+=x;
        }
        if(g)r++;//当前局势先手必胜 相当于r+1
        if(r>b)puts("YES");
        else puts("NO");
    }
    return 0;
}
Published 43 original articles · won praise 0 · Views 1245

Guess you like

Origin blog.csdn.net/Yubing792289314/article/details/104271872
Recommended