HDU 1524 A Chess Game (SG function)

Source: Internet
Author: User

Problem Description:

Let ' s design a new chess game. There is N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The positions is constituted as a topological graph, i.e. there is directed edges connecting some positions, and no CYCL E exists. II Players you and I move chesses alternately. In each turn the player should move is only a chess from the current position to one of its out-positions along an edge. The game does not end, until one of the players cannot move chess any more. If You cannot move any chess in your turn, you lose. Otherwise, if the misfortune falls on me ... I'll disturb the chesses and play it again.
Do you want to challenge me? Just Write your program to show your qualification!

Input:

Input contains multiple test cases. Each test case is starts with a number n (1 <= n <=) on one line. Then the following N lines describe the out-positions of each position. Each line starts with a integer Xi is the number of out-positions for the position I. Then Xi integers following specify the out-positions. Positions is indexed from 0 to N-1. then multiple queries follow. Each query is occupies only one line. The line starts with a number M (1 <= m <=), and then come M integers, which is the initial positions of chesses . A line with number 0 ends the test case.

Output:

There is one line for each query, which contains a string "WIN" or "Lose". "Win" means that the player taking the first turn can WIN the game according to a clever strategy; Otherwise "lose" should be printed.

Sample Input:

4
2 1 2
0
1 3
0
1 0
2 0 2
0

4
1 1
1 2
0
0
2 0 1
2 1 1
3 0 1 3
0

Sample Output:

WIN
WIN
WIN
Lose
WIN

#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath > #include <vector> #include <map> #include <set>using namespace Std;const int maxn = + 10;vector&    Lt;int>g[maxn];int Sg[maxn];int Mex (int x) {if (sg[x]! =-1) return sg[x];    BOOL VIS[MAXN];    memset (Vis, 0, sizeof (VIS));    int sz = G[x].size ();    for (int i=0;i<sz;i++) Vis[mex (g[x][i]) = 1; for (int i=0;;        i++) if (!vis[i]) {sg[x] = i;    Break } return sg[x];}    int main () {int n;        while (cin>>n) {memset (SG,-1, sizeof (SG));        for (int i=0;i<n;i++) g[i].clear ();            for (int i=0;i<n;i++) {int m;            cin>>m;                while (m--) {int x;                cin>>x;            G[i].push_back (x);        }} int Q;    while (CIN&GT;&GT;Q) {if (Q = = 0) break;        int ans = 0;                while (q--) {int x;                cin>>x;            Ans ^= Mex (x);            } if (ans) puts ("WIN");        Else puts ("Lose"); }} return 0;}


HDU 1524 A Chess Game (SG function)

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.