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");
             }
        }
    }

  • 相关阅读:
    【转】ORACLE Dataguard安装
    win7 配置微软的深度学习caffe
    深度学习-开源方案
    Python之包管理工具
    C#调用Python脚本的简单示例
    转Python 和C#的交互
    转-使用 CefSharp 在 C# App 中嵌入 Chrome 浏览器
    转-在Mac OS上搭建Python的开发环境
    Weex入门与进阶指南
    A couple of notes about .NET Framework 4.6 setup behaviors
  • 原文地址:https://www.cnblogs.com/dchipnau/p/4985971.html
Copyright © 2011-2022 走看看