hdu 1524

 

    一道博弈sg的题,做完感觉到sg果然是博弈中的王道,感觉稀奇古怪的题往nim上靠,然后再分解,然后在异或就ok啦

 

 

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int c[1001][1001];
int sg[1001];
int n_point;
int getsg(int a)
{
    if(sg[a]!=-1)
        return sg[a];
    int hand[100];
    memset(hand,0,sizeof(hand));
    int i;
    for(i=0;i<n_point;i++)
         if(c[a][i]==1)
            hand[getsg(i)]=1;
    for(i=0;;i++)
         if(!hand[i])
             return sg[a]=i;
}
int main()
{
    while(scanf("%d",&n_point)!=EOF)
    {
         int i,j;
         memset(c,0,sizeof(c));
         memset(sg,-1,sizeof(sg));
         for(i=0;i<n_point;i++)
         {
             int n;
             scanf("%d",&n);
             if(n==0)
                 sg[i]=0;
             for(j=0;j<n;j++)
             {
                 int a;
                 scanf("%d",&a);
                 c[i][a]=1;
             }
         }
         int n;
         while(scanf("%d",&n),n)
         {
              int m;
              int i;
              for(i=0;i<n;i++)
              {
                  int a;
                  scanf("%d",&a);
                  if(i==0)
                     m=getsg(a);
                  else
                     m^=getsg(a);
              }
              if(m==0)
                  printf("LOSE\n");
              else
                  printf("WIN\n");
         }
    }
}

 

posted @ 2011-09-14 18:05  DChipNau  阅读(100)  评论(0编辑  收藏  举报