SG博弈简单题


ZOJ - 2083 - Win the Game

题目传送:Win the Game

最近正在慢慢体会博弈里面的SG函数的意义

此题是最简单的SG博弈问题,只需打个表就OK了

AC代码:

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#define LL long long
#define INF 0x7fffffff
using namespace std;

int sg[55];
int vis[55];

void get_sg() {
    sg[0] = 0;
    sg[1] = 0;
    for(int i = 2; i < 55; i ++) {
        memset(vis, 0, sizeof(vis));
        vis[sg[i - 2]] = 1;
        for(int j = 1; j + 2 <= i; j ++) {
            vis[sg[j] ^ sg[i - j - 2]] = 1;
        }
        for(int j = 0;; j ++) {
            if(!vis[j]) {
                sg[i] = j;
                break;
            }
        }
    }
}

int n;

int main() {
    get_sg();
    //for(int i = 0; i < 55; i ++) cout << sg[i] << " ";
    while(scanf("%d", &n) != EOF) {
        int SG = 0, t;
        for(int i = 0; i < n; i ++) {
            scanf("%d", &t);
            SG ^= sg[t];
        }
        if(SG == 0) {
            printf("No\n");
        }
        else printf("Yes\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-21 11:38:49

SG博弈简单题的相关文章

hdu 1524 A Chess Game 博弈之,SG函数简单题

A Chess Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1489    Accepted Submission(s): 679 Problem Description Let's design a new chess game. There are N positions to hold M chesses in th

hdu 1846 Brave Game (巴什博弈 最简单的博弈水题)

Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6434    Accepted Submission(s): 4294 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分

【POJ2960】S-Nim SG函数 博弈 裸题模板题

转载请注明出处:http://blog.csdn.net/vmurder/article/details/42653601 其实我就是觉得原创的访问量比未授权盗版多有点不爽233... 题意: 两人轮流从若干堆石子中某堆取k个石子, k∈集合S, 就是每次取的数量被限定成某几个数的意思! 然后跟正常Nim一样谁不能操作就输. 题解: SG函数裸题. SG函数: 首先需要是有向无环图(拓扑图) 首先确定边界状态,SG值为0,然后暴力拓扑得出其它点的SG值. SG值为所有子集的SG值中未出现的最小自

数论 --- 简单题

吃糖果 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 22376    Accepted Submission(s): 6396 Problem Description HOHO, 终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一 种,这样:

HDU 1848(sg博弈) Fibonacci again and again

Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6253    Accepted Submission(s): 2603 Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(2)

POJ 2234 Matches Game(Nim博弈裸题)

Description Here is a simple game. In this game, there are several piles of matches and two players. The two player play in turn. In each turn, one can choose a pile and take away arbitrary number of matches from the pile (Of course the number of mat

poj2105 IP Address(简单题)

题目链接:http://poj.org/problem?id=2105 Description Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1s' and '0s' (bits) to a dotted decimal format. A dotted decima

poj 3270 Cow Sorting 置换群 简单题

假设初始状态为 a:2 3 1 5 4 6 则目标状态为 b:1 2 3 4 5 6且下标为初始状态中的3 1 2 4 5 6(a[3],a[1]...) 将置换群写成循环的形式 (2,3,1),(5,4),6就不用移动了. 移动方式2种 1:选循环内最小的数和其他len-1个数交换 2:选整个序列最小的数和循环内最小的数交换,转到1,再换回来. #include<cstdio> #include<queue> #include<algorithm> #include&

BZOJ 2683 简单题 ——CDQ分治

简单题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define F(i,j,k) for (int i=j;i<=k;++i) #define D(i,j,k) for (int i=j;i>=k;--i) #define maxn 2000005 int sum[maxn]; void a