Sequential Nim【博弈】

题目链接CF-1382-B


  题意:有N个石子堆,每个石子堆有a[i]个石子,现在从第一堆开始往后取,谁最先没法取石子,谁就输了,问最后谁先手还是后手赢了?

  于是乎,可以看到,影响胜负的只有开局的为1的石子个数,就譬如说第一个石头不为1,那么我们就可以控制了,是取成一个其他数来匹配后面的,还是直接取完,然后他就一定能获胜了,所以真正影响胜负的,是谁开始控制局面,怎么控制,就是第一堆“>1”的石子堆(因为他是知道后继石子堆的),所以就可以开始控制了。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 1e5 + 7;
const char name[2][7] = {"First", "Second"};
int N, a[maxN];
int main()
{
    int T; scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &N);
        for(int i=1; i<=N; i++) scanf("%d", &a[i]);
        int op = 0;
        for(int i=1; i<N; i++)
        {
            if(a[i] == 1) op ^= 1;
            else break;
        }
        printf("%s\n", name[op]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41730082/article/details/107505778