HDU 4559 Coloring Game (SG)

Source: Internet
Author: User

Stain on a 2*n grid every time a lattice or 2*2 lattice that can dye 1*1 is the most full of all the squares. M is the number of stained squares Alice initiator

The 1*1 point SG value of 1 SG "I" means the SG value of continuous 2*i SG "3" is a continuous 2*3 blank lattice

If n = 3
The case of a 1*1 lattice, then the subsequent state may be
State 1 Continuous 0-column lattice + continuous 2-column grid + remaining that column coated with 1 lattices
State 2 continuous 1-column lattice + continuous 1-column grid + remaining that column coated with 1 lattices

The case of a 2*3 lattice, then the subsequent state may be
State 1 Continuous 0-column lattice + continuous 1-column lattice + remaining 2*2 lattice

Finally, the whole checkerboard is segmented continuously blank 2*i lattice and a column of the color-coated lattice

Sample Input
2
2 0//N m
2 2//n m
1 1//The coordinates of the dyed lattice
2 2

Sample Output
Case 1:alice
Case 2:bob

1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <string>6# include <cmath>7# include <queue>8# include <list>9# define LLLong LongTen using namespacestd; One Const intmaxn= the; A intSG[MAXN]; - BOOLVIS[MAXN]; - BOOLg[2][MAXN]; the intMexintx) - { -     if(sg[x]!=-1)returnSg[x]; -memset (Vis,false,sizeof(Vis)); +      for(intI=0; i<=x-1-i;i++)//Dye 1*1 -     { +         intTmp=mex (i) ^mex (X-1-i) ^1; Avis[tmp]=true; at     } -      for(intI=0; i<=x-2-i;i++)//Dye 2*2 -     { -         intTmp=mex (i) ^mex (X-2-i); -vis[tmp]=true; -     } in      for(intI=0;; i++) -         if(!Vis[i]) to         { +sg[x]=i; -              Break; the         } *     returnSg[x]; $ }Panax Notoginseng  - intMain () the { +  Amemset (sg,-1,sizeof(SG)); thesg[0]=0; +      for(intI=1;i< the; i++) -sg[i]=Mex (i); $     intT; $scanf"%d",&T); -     intIcase=0; -      while(t--) the     { -         intn,m;Wuyiscanf"%d%d",&n,&m); theMemset (G,false,sizeof(g)); -         intu,v; Wu          while(m--) -         { Aboutscanf"%d%d",&u,&v); $u--;v--; -g[u][v]=true; -         } -         intlen=0; A         intans=0; +          for(intI=0; i<n;i++) the         { -             if(g[0][i]| | g[1][i]) $             { theans^=Sg[len]; thelen=0; the                 if(g[0][i]&&g[1][i])Continue; theans^=1; -             } in             Elselen++; the         } theans^=Sg[len]; Abouticase++; the         if(ANS) printf ("Case %d:alice\n", icase); the         Elseprintf"Case %d:bob\n", icase); the     } +     return 0; -}
View Code

HDU 4559 Coloring Game (SG)

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.