思路:三维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 + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
int m[][] = {, , , };
int Nim_Mul_Power(int x, int y){
if(x < ) return m[x][y];
int a = ;
for(; ; a++){
if(x >= ( << ( << a)) && x < ( << ( << (a + ))))
break;
}
int m = << ( << 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 / , d1);
}
int Nim_Mul(int x, int y){
if(x < y) return Nim_Mul(y, x);
if(x < ) return m[x][y];
int a = ;
for(; ; a++){
if(x >= ( << ( << a)) && x < ( << ( << (a + ))))
break;
}
int m = << ( << 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 / , 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 = ;
int x, y, z;
while(n--){
scanf("%d%d%d", &x, &y, &z);
ans ^= Nim_Multip(x, y, z);
}
if(ans)
printf("No\n");
else
printf("Yes\n");
}
return ;
}

POJ 3533 Light Switching Game(三维Nim积)题解的更多相关文章

  1. POJ 3553 Light Switching Game 博弈论 nim积 sg函数

    http://poj.org/problem?id=3533 变成三维的nim积..前面hdu那个算二维nim积的题的函数都不用改,多nim积一次就过了...longlong似乎不必要但是还是加上了 ...

  2. HDU 3404&POJ 3533 Nim积(二维&三维)

    (Nim积相关资料来自论文曹钦翔<从"k倍动态减法游戏"出发探究一类组合游戏问题>) 关于Nim积计算的两个函数流程: 代码实现如下: ][]={,,,}; int N ...

  3. Nim积解法小结

    由于某毒瘤出题人 redbag 不得不学习一下这个史诗毒瘤算法. 本文参考了 Owaski 的 GameTheory 的课件. 定义 我们对于一些二维 \(\mathrm{Nim}\) 游戏(好像更高 ...

  4. HDU 3404 Switch lights(Nim积)题解

    题意:在一个二维平面中,有n个灯亮着并告诉你坐标,每回合需要找到一个矩形,这个矩形xy坐标最大的那个角落的点必须是亮着的灯,然后我们把四个角落的灯状态反转,不能操作为败 思路:二维Nim积,看不懂啊, ...

  5. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  6. HDU 3404 Switch lights 博弈论 nim积

    http://acm.hdu.edu.cn/showproblem.php?pid=3404 题目 http://www.doc88.com/p-5098170314707.html 论文 nim积在 ...

  7. 洛谷——P2846 [USACO08NOV]光开关Light Switching

    P2846 [USACO08NOV]光开关Light Switching 题目大意: 灯是由高科技——外星人鼠标操控的.你只要左击两个灯所连的鼠标, 这两个灯,以及之间的灯都会由暗变亮,或由亮变暗.右 ...

  8. Nim积的一种???的写法

    Nim积总不能一直打四次暴力吧! 用SG定理等东西,可以证明 \((N, \oplus, \otimes)\) 构成一个域.(证明很难,我不会) 其中 \(\oplus\) 为异或, \(x \oti ...

  9. 洛谷P2826 [USACO08NOV]光开关Light Switching [2017年6月计划 线段树02]

    P2826 [USACO08NOV]光开关Light Switching 题目描述 Farmer John tries to keep the cows sharp by letting them p ...

随机推荐

  1. CSS 基础知识

    CSS 实例(CSS声明总是以分号(;)结束,声明组以大括号({})括起来:) CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明: 选择器通常是您需要改变样式的 HTML 元素. 每条声明 ...

  2. HDU5012:Dice(bfs模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 Problem Description There are 2 special dices on the ...

  3. Linux环境下解压rar文件

    可以用unrar命令解压rar后缀的文件 unrar e test.rar 解压文件到当前目录 unrar x test.rar /path/to/extract unrar l test.rar 查 ...

  4. 20180531-Postman 常用测试结果验证及使用技巧

  5. 什么时候block 是放在全局区里面的?

    When a Block literal is written where there are global variables When the syntax in a Block literal ...

  6. 网站nginx负载下因程序错误导致多节点重复处理请求的解决过程

    目录 前言 问题来了 问题又来了 问题分析 困惑 转机 后续 前言: 这是我上周工作过程中的一次解决问题的过程.解决的是nginx负载环境下,因为应用程序异常导致某一请求被多节点站点重复处理的问题. ...

  7. BinarySearch

    今天看代码,看到这么一段,开始没有看明白,记录下来备忘 foreach (FinancialReport r3 in addAorList)            {                i ...

  8. ef延迟加载不到导航属性问题

    最近做项目踩到了一个ef问题上的坑,导航属性(外键关键,如子表或主表等)“.”出来后是Null,外键值也对,数据库和ef的关系配置也都正确,就是加载不出来.后来发现实体里导航属性前少了个virtual ...

  9. xhtml 的三种 doctype

    {1}文档宣告 <!ODCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 [there]//EN" "http://www.w4org/TR/xhtml1/DTD/ ...

  10. animation效果

    添加一个颜色灰渐变的动画效果. <!DOCTYPE html><html lang="en"><head> <meta charset=& ...