hdu-5724 Chess (combo game)

Source: Internet
Author: User

Topic Links:

Chess

Time limit:2000/1000 MS (java/others)

Memory limit:65536/65536 K (java/others)


Problem Descriptionalice and Bob is playing a special chess game on an nx20 chessboard. There is several chesses on the chessboard. They can move one chess in one turn. If There is no other chesses on the right adjacent blocks of the moved chess, move the chess to their right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. The chesses can ' t is placed at one block and no chess can is placed out of the chessboard. When someone can ' t move any chess during his/her turn, he/she'll lose the game. Alice always take the first turn. Both Alice and Bob would play the game with the best strategy. Alice wants to know if she can win the game.

Inputmultiple test Cases.

The first line contains an integerT(t≤) , indicates the number of test cases.

For each test case, the first line contains a single integern(n≤) The number of lines of chessboard.

ThenNLines, the first integer of ith line ism(m≤) , indicates the number of chesses on the ith line of the chessboard. Then M integers< Span id= "mathjax-span-29" class= "Mrow" > pj (1≤ pj≤20) followed, the position of each Chess.

Outputfor each test case, output one line of "YES" if Alice can win the game, "NO" otherwise.

Sample Input 212 19 2021 191 18

Sample Output NOYES Test instructions: To a n*20 board, a piece of each row of the lattice inside, now each time you can choose a piece to move it to the right of the first vacancy; now ask whether the initiator can win;
Thinking: The content of the combination game, first of all the status of the SG function value, and then take the difference or value to determine whether it is zero; AC Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath>//#include <bits/stdc++.h> #include <stack>using namespace std; #define for (i,j,n) for (int i=j;i <=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long LONG ll;template<class t> void Read (T&num)    {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;}    while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=2e6+10;const int Maxn=500+10;const double eps=    1e-8;int sg[n],vis[25];inline int Get_sg (int x) {MST (vis,0);    cout<<x<<endl; for (int i=19;i>=0;i--) {if(x& (1<<i))            {int temp=x; for (int j=i-1;j>=0;j--) {if (!) (                    x& (1<<j)) {temp^= (1<<i) ^ (1&LT;&LT;J);                    cout<<temp<<endl;                    Vis[sg[temp]]=1;                Break    }}}} for (int i=0;i<=19;i++) if (!vis[i]) return i; return 0;} inline void Init () {for (i,0, (1<<20)-1) sg[i]=get_sg (i);}        int main () {Init ();        int t;        Read (t);            while (t--) {int n,a,m,ans=0;            Read (n);                while (n--) {int sum=0;                Read (m);                    for (i,1,m) {read (a);                Sum|= (1<< (20-a));            } Ans^=sg[sum];            } if (ans) printf ("yes\n");        else printf ("no\n");  } return 0;}

  

hdu-5724 Chess (combo game)

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.