zoukankan      html  css  js  c++  java
  • POJ 3533 Light Switching Game(三维Nim积)题解

    思路:三维Nim积

    代码:

    #include<set>
    #include<map>
    #include<stack>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    typedef long long ll;
    const int maxn = 1e6 + 10;
    const int seed = 131;
    const ll MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    int m[2][2] = {0, 0, 0, 1};
    int Nim_Mul_Power(int x, int y){
        if(x < 2) return m[x][y];
        int a = 0;
        for(; ; a++){
            if(x >= (1 << (1 << a)) && x < (1 << (1 << (a + 1))))
                break;
        }
        int m = 1 << (1 << a);
        int p = x / m, s = y / m, t = y % m;
        int d1 = Nim_Mul_Power(p, s);
        int d2 = Nim_Mul_Power(p, t);
        return (m * (d1 ^ d2)) ^ Nim_Mul_Power(m / 2, d1);
    }
    int Nim_Mul(int x, int y){
        if(x < y) return Nim_Mul(y, x);
        if(x < 2) return m[x][y];
        int a = 0;
        for(; ; a++){
            if(x >= (1 << (1 << a)) && x < (1 << (1 << (a + 1))))
                break;
        }
        int m = 1 << (1 << a);
        int p = x / m, q = x % m, s = y / m, t = y % m;
        int c1 = Nim_Mul(p, s), c2 = Nim_Mul(p, t) ^ Nim_Mul(q, s), c3 = Nim_Mul(q, t);
        return (m * (c1 ^ c2)) ^ c3 ^ Nim_Mul_Power(m / 2, c1);
    }
    int Nim_Multip(int x, int y, int z){
        return Nim_Mul(Nim_Mul(x, y), z);
    }
    int main(){
        int n, ans;
        while(~scanf("%d", &n)){
            ans = 0;
            int x, y, z;
            while(n--){
                scanf("%d%d%d", &x, &y, &z);
                ans ^= Nim_Multip(x, y, z);
            }
            if(ans)
                printf("No
    ");
            else
                printf("Yes
    ");
        }
        return 0;
    }
  • 相关阅读:
    面试题目
    MyEclipse 启动 tomcat时错误处理
    js 剪贴板操作
    PHP面试题
    MySQL 数据库 source 导入乱码
    php 不用通过表单也能创建HTTPpost请求
    一个css中zindex的用法
    最新黑链代码expression:隐藏链接代码
    测试网站访问速度的几个小方法
    优秀开源外贸网店程序一览
  • 原文地址:https://www.cnblogs.com/KirinSB/p/9698941.html
Copyright © 2011-2022 走看看