HDU 1524 A Chess Game (directed acyclic graph SG Game)

Source: Internet
Author: User

Reprint please indicate the source, thank you http://blog.csdn.net/ACM_cxlove? Viewmode = contents by --- cxlove
This is a game against Directed Acyclic graphs.
Question: There are N locations in which there is a topological relationship, which must be observed when moving. Finally, the mobile app wins and asks if there is a winning strategy
Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1524
A directed acyclic graph. The SG function of a vertex is the smallest of its successor nodes. (MEX operation ).
It is the same as finding a common SG function.
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Define N 10005
# Define LL long
# Define inf 1 <29
# Define eps 1e-7
Using namespace std;
Vector <int> v [1005];
Int n, sg [1005];
Int get_sg (int n ){
If (sg [n]! =-1)
Return sg [n];
If (v [n]. size () = 0)
Return 0;
Int vis [1005];
Memset (vis, 0, sizeof (vis ));
For (int I = 0; I <v [n]. size (); I ++ ){
Sg [v [n] [I] = get_sg (v [n] [I]);
Vis [sg [v [n] [I] = 1;
}
For (int I = 0; I ++)
If (vis [I] = 0)
Return I;
}
Int main (){
While (scanf ("% d", & n )! = EOF ){
Memset (sg,-1, sizeof (sg ));
For (int I = 0; I <n; I ++ ){
V [I]. clear ();
Int k, u;
Scanf ("% d", & k );
While (k --){
Scanf ("% d", & u );
V [I]. push_back (u );
}
}
Int q, k, u;
While (scanf ("% d", & k ){
Int ret = 0;
While (k --){
Scanf ("% d", & u );
If (sg [u] =-1)
Sg [u] = get_sg (u );
Ret ^ = sg [u];
}
If (ret = 0)
Puts ("LOSE ");
Else
Puts ("WIN ");
}
}
Return 0;
}
By ACM_cxlove

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.