zoukankan      html  css  js  c++  java
  • 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");
             }
        }
    }

  • 相关阅读:
    HDU 5585 Numbers
    HDU 3308 LCIS
    POJ 2991 Crane
    POJ 1436 Horizontally Visible Segments
    POJ 3667 Hotel
    HaiHongOJ 1003 God Wang
    【SDOI 2008】 递归数列
    5月19日省中提高组题解
    【HDU 1588】 Gauss Fibonacci
    【POJ 3233】Matrix Power Series
  • 原文地址:https://www.cnblogs.com/dchipnau/p/4985980.html
Copyright © 2011-2022 走看看