zoukankan      html  css  js  c++  java
  • HDU6886 -Tic-Tac-Toe-Nim (思维,博弈)

    HDU6886 -Tic-Tac-Toe-Nim (思维,博弈)

    题面:

    题意:

    多组数据,每一组数据给你一个(3 imes 3) 的方格,每一个方法初始有一定量的石头,二人轮流选择一个非空石堆,然后移除至少一个石头,当一个玩家操作后产生了一行或一列全为空时,该玩家输掉。

    特别的:两个玩家第一次选择时,必须将该堆石头全部移除。

    问有多少位置时先手选择它可以接下来必胜。

    思路:

    我们观察题目,当一个玩家操作后产生了一行或一列全为空时,该玩家输掉,因此在每一次操作后,我们都可以交换任意行和列,不影响答案。

    那么对于任意前两步操作,我们都可以将其移动成((1,1),(2,2))被移走的情况,那么接下来,

    ((1,2),(1,3),(2,1),(2,3),(3,1),(3,2)),哪个玩家取走这些位置中的最后一个石子,显然就会输掉比赛,

    那么问题就转化为了(a_{1,2}-1,a_{1,3}-1,a_{2,1}-1,a_{2,3}-1,a_{3,1}-1,a_{3,2}-1,a_{3,3})这些数字组成的nim博弈问题。

    后手必赢的条件就是这些数字异或起来为0。那么我们只需要枚举一下前两步的位置节课得出答案。

    代码:

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <bits/stdc++.h>
    #define ALL(x) (x).begin(), (x).end()
    #define sz(a) int(a.size())
    #define rep(i,x,n) for(int i=x;i<n;i++)
    #define repd(i,x,n) for(int i=x;i<=n;i++)
    #define pii pair<int,int>
    #define pll pair<long long ,long long>
    #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    #define MS0(X) memset((X), 0, sizeof((X)))
    #define MSC0(X) memset((X), '', sizeof((X)))
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define eps 1e-6
    #define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
    #define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
    #define du2(a,b) scanf("%d %d",&(a),&(b))
    #define du1(a) scanf("%d",&(a));
    using namespace std;
    typedef long long ll;
    ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
    ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
    ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
    ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
    void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("
    ");}}}
    void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("
    ");}}}
    inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
    inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
    void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '
    ' : ' ');}}
    void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '
    ' : ' ');}}
    const int maxn = 1000010;
    const int inf = 0x3f3f3f3f;
    /*** TEMPLATE CODE * * STARTS HERE ***/
    #define DEBUG_Switch 0
    int n = 3;
    int a[10][10];
    int main()
    {
    #if DEBUG_Switch
        freopen("C:\code\input.txt", "r", stdin);
    #endif
        //freopen("C:\code\output.txt","w",stdout);
        int t;
        t = readint();
        while (t--)
        {
            int val = 0;
            repd(i, 1, n)
            {
                repd(j, 1, n)
                {
                    a[i][j] = readint();
                    val ^= (a[i][j] - 1);
                }
            }
            int ans = 0;
            repd(x0, 1, n)
            {
                repd(y0, 1, n)
                {
                    int flag = 1;
                    repd(x1, 1, n)
                    {
                        if (x1 == x0)
                            continue;
                        repd(y1, 1, n)
                        {
                            if (y1 == y0)
                                continue;
                            if ((val ^ (a[x0][y0] - 1) ^ (a[x1][y1] - 1) ^ (a[6 - x1 - x0][6 - y1 - y0] - 1)^a[6 - x1 - x0][6 - y1 - y0]) == 0)
                            {
                                flag = 0;
                            }
                        }
                    }
                    ans += flag;
                }
            }
            printf("%d
    ", ans );
        }
    
        return 0;
    }
    
    
    
    
    本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
  • 相关阅读:
    数据结构总结(UPDATING......)
    课件例题4.11,4.12
    Luogu P1525 关押罪犯
    Luogu P1540 机器翻译
    Luogu P1313 计算系数
    Luogu P1311 选择客栈
    Luogu P1519 穿越栅栏 Overfencing
    Luogu P2863 [USACO06JAN]牛的舞会The Cow Prom
    Tarjan学习笔记
    Luogu P3393 逃离僵尸岛
  • 原文地址:https://www.cnblogs.com/qieqiemin/p/13574755.html
Copyright © 2011-2022 走看看