zoukankan      html  css  js  c++  java
  • 博弈论入门基础

    看了别人的博客,非常通俗易懂啊,从Nim 博弈开始讲的,讲述了关于 Nim 博弈的策略,还有 sg 值的作用及推导,然后讲解了Nim 博弈的变形,很好玩

    http://blog.csdn.net/flqbestboy/article/details/8222603

    有很大收获,记录一波!

    然后来做个题目:小Hi和小Ho的对弈游戏

    树的删边游戏,sg 值的运用,最后还是归到 Nim 博弈上来

    还是不会可以看看 http://blog.sina.com.cn/s/blog_51cea4040100h5j4.html

    此题代码:

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <vector>
     6 using namespace std;
     7 #define MX 100005
     8 
     9 int f[MX];
    10 vector<int> son[MX];
    11 int sg[MX];
    12 char ans[30];
    13 
    14 void dfs(int x)
    15 {
    16     for (int i=0;i<son[x].size();i++)
    17         dfs(son[x][i]);
    18     sg[x]=0;
    19     for (int i=0;i<son[x].size();i++)
    20         sg[x] ^= (sg[son[x][i]]+1);
    21 }
    22 
    23 int main()
    24 {
    25     int Q;
    26     cin>>Q;
    27     int k=0;
    28     while (Q--)
    29     {
    30         int n;
    31         scanf("%d",&n);
    32         for (int i=1;i<=n;i++) f[i]=i;
    33         for (int i=1;i<=n;i++) son[i].clear();
    34 
    35         for (int i=0;i<n-1;i++)
    36         {
    37             int x,y;
    38             scanf("%d%d",&x,&y);
    39             f[y]=x;
    40             son[x].push_back(y);
    41         }
    42         int root;
    43         for (int i=1;i<=n;i++)
    44             if (f[i]==i)
    45             root=i;
    46         dfs(root);
    47 
    48         if (sg[root]==0)
    49             ans[k++]='0';
    50         else
    51             ans[k++]='1';
    52 
    53         int tp=0;
    54         for (int i=0;i<son[root].size();i++)
    55              tp^=sg[son[root][i]];
    56         if (tp==0)
    57             ans[k++]='0';
    58         else
    59             ans[k++]='1';
    60     }
    61     ans[k++]='';
    62     printf("%s
    ",ans);
    63     return 0;
    64 }
    View Code
  • 相关阅读:
    Windows 网络监测ping IP输出时间
    python
    遇见问题汇总
    在路上积累
    Condition
    ReentrantReadWriteLock
    AbstractQueuedSynchronizer
    jmeter使用
    使用VisualVM监控java进程
    CNVD漏洞证书(2)
  • 原文地址:https://www.cnblogs.com/haoabcd2010/p/7272976.html
Copyright © 2011-2022 走看看