Before introducing the SG function and the SG theorem, let's introduce the winning and losing points.the concept of winning points and losing points:P-Point: Must lose the point, in other words, is who is in this position, then in both sides operation correct situation will defeat.N Point: Win point, in this case, both sides operate correctly under the circumstances to win.the nature of winning and losing p
Topic links #include #include#includeusing namespacestd;intsg[ .];intGET_SG (intN) { if(n0)return 0; if(sg[n]!=-1)returnSg[n]; BOOLvis[ .]; //inexplicable! //vis[] Array to be declared in the function, if put outside will WAmemset (Vis,0,sizeof(VIS)); for(intI=1; i) Vis[get_sg (n-i-2) ^get_sg (I-3)]=1;//Sub-situation is different or//each one x, the left and right of the two lattice can not be selected, that is, five cells can not be selected//so
HDU 3595 GG and MM (Every-SG), hduevery-sg
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission (s): 805 Accepted Submission (s): 367Problem DescriptionGG and MM like playing a game since they are children. at the beginning of game, there are two piles of stones. MM chooses a pile of stones first, which has x stones, and then she can choose a positive number k and
1. SQL BasicsGo to the check-gaps phase2. PL/SQLEnter the practice stage3. Fundamental 1This part is still more important.ArchitectureDatabase Startup and shutdown stepsinstance and parameter fileCreate DATABASE Manual and DBCAComparison of commonly used data dictionariesMultiplexing of control fileRedo log File structureTablespace DataFile FeaturesCharacteristics of storage such as physical blocksStructure and characteristics of undoManage Tables TableManage IndexesManage Data consistencyManag
Given a piece with a direction-free graph and a starting vertex, the two players alternately move the piece along a forward edge and cannot be judged negative by the mover. In fact, this game can be thought of as an abstract model of all impartial combinatorial games. In other words, any ICG can be abstracted into this "graph game" by taking each situation as a vertex and a forward edge to each situation and its sub-situation. Below we define the Sprague-grundy function on the vertex with the di
First defines the MEX (minimal excludant) operation, which is an operation exerted on a set, representing the smallest nonnegative integer that does not belong to this set. For example
Mex{0,1,2,4}=3, Mex{2,3,5}=0, mex{}=0.
For a given direction-free graph, the sprague-grundy function for each vertex of the graph is defined as follows: g (x) =mex{g (y) | Y is the successor of X, where G (x) is
SG[X].
For example: To take the stone problem, there are
I haven't had a game in a long time. To write a template first:Now let's look at a game that seems more general: given a piece with a direction-free graph and a starting vertex, the two players alternately move the piece along a forward edge and cannot be judged negative by the moving side. In fact, this game can be thought of as an abstract model of all impartial combinatorial games. In other words, any ICG can be abstracted into this " graph game "by taking each situation as a vertex and a for
I haven't had a game in a long time. To write a template first:Now let's look at a game that seems more general: given a piece with a direction-free graph and a starting vertex, the two players alternately move the piece along a forward edge and cannot be judged negative by the moving side. In fact, this game can be thought of as an abstract model of all impartial combinatorial games. In other words, any ICG can be abstracted into this " graph game "by taking each situation as a vertex and a for
a integer N, indicating the number of the heaps, the next line contains N integers s[0], s[1], .... , S[n-1], representing heaps with s[0], s[1], ..., s[n-1] objects respectively. (1≤n≤10^6, 1≤s[i]≤2^31-1)Outputfor each test case, output a line which contains either "Alice" or "Bob", which are the winner of this game. Alice would play first. Asume they never make mistakes.Sample Input232 2 323 3Sample OutputAlicebobSource2009 multi-university Training Contest 13-host by hitsMain topic:
can win, please output "Fibo", otherwise output "Nacci", the output of each instance takes up one row.
Sample Input1 1 11 4 10 0 0
Sample OutputFiboNacci
Thinking Analysis:This question is quite good.The entry question for the SG function.The MEX (minimal excludant) operation is defined first, which is an operation applied to a set that represents the smallest non-negative integer that does not belong to this set. such as Mex{0,1,2,4}=3, Mex{2,3,5}
integer N, indicating the number of the heaps, the next line contains N integers s [0], s [1],..., s [N-1], representing heaps with s [0], s [1],..., s [N-1] objects respectively. (1 ≤ n ≤ 10 ^ 6, 1 ≤ S [I] ≤ 2 ^ 31-1)
Outputfor each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes.
Sample Input
232 2 323 3
Sample output
AliceBob
Source2009 multi-university training contest 13-host by
will win.The Input data contains multiple test cases. Each test case occupies one row and contains three integers, m, n, p (1 M = n = p = 0 indicates that the input ends.Output: if the first player can win the game, Output "Fibo"; otherwise, Output "Nacci". The Output of each instance occupies one line.Sample Input
1 1 11 4 10 0 0Sample Output
FiboNacciAuthorlcy SourceACM Short Term Exam_2007/12/13 Question: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1848
The first question with the
Although this article is reproduced, but the code and the original is not the same, I think my code is better.Reprinted from:http://www.cnblogs.com/frog112111/p/3199780.htmlThe MEX (minimal excludant) operation is defined first, which is an operation applied to a set that represents the smallest non-negative integer that does not belong to this set. such as Mex{0,1,2,4}=3, Mex{2,3,5}=0, mex{}=0.For a given, forward-free graph, define the Sprague-grundy function g for each vertex of the graph as
."
Sample Input511310 11 1251 2 3) 4 524 931 3 9Sample OutputCase 1:bobCase 2:aliceCase 3:aliceCase 4:bobCase 5:alice Test Instructions
There are n heap of stones, Alice Initiator, the two sides take turns, each time can be taken not more than half of the stone walk, who can not take the idea of who lose
Data range is very large, direct hit the table certainly not, that must have the law, then we first dozen SG value to look for the law
int
its sub-situation into a directed graph game ". The following is defined on the vertex of a directed acyclic graph.SD-garundyFunction.
First define the Mex (minimal excludant) operation, which is applied to a set operation,The smallest non-negative integer that does not belong to this set. For example, Mex {0, 1, 2, 4} = 3, Mex {2, 3, 5} = 0, and Mex {} = 0.
For a givenDirected acyclic graph,The following figure shows the description of the SD-garundy function g for each vertex in the graph.:
must be no valid movement. After AI is changed to AI, A1 ^ A2 ^... ^ AI '^... ^ An = 0. Because the exclusive or operation satisfies the elimination rate, it is determined by a1 ^ A2 ^... ^ An = A1 ^ A2 ^... ^ AI '^... ^ An can get Ai = AI '. Changing AI to AI is not a legal move. Pass.
According to this theorem, we can judge the nature of a nim situation in O (n) time. If it is n-position, it can also be in O (N) find all winning strategies in time. The Nim problem is basically perfectly solve
the nature of SG functions. First, all the vertex corresponding to the terminal position, that is, the vertex without an outbound edge, and its SG value is 0, because its successor set is an empty set. Then for a vertex x whose g (x) = 0, all its successor y satisfies g (y )! = 0. For a G (x )! = 0 vertex, there must be a successor y to meet G (y) = 0.The above three statements show that the postion repres
-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}
test cases.For each test case:the first line contains a number k (0 The last test case was followed by a 0 on a line of its own.OutputFor each position:if the described position is a winning position print a ' W '. If the described position is a losing position print a ' L '.Print a newline after all test case.Sample Input2 2 532 5 123 2 4 74 2 3 7 125 1 2 3 4 532 5 123 2 4 74 2 3 7 120Sample OutputLwwwwlThe classic NIM game title has been given--there is no limit to the number of selections in
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1847
This is exactly the same as toj1180.
Use the SG function. Enter the SG value in 1000 to the table.
Code:/* # Include Int main (){
Int N;
While (~ Scanf ("% d", N )){
If (N % 3) printf ("Kiki \ n ");
Else printf ("Cici \ n ");
}
Return 0;
}*/
# Include # Include Int SG [1001], a [11];
Void Init (){
Memset (
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.