HDU 3404 Switch lights(Nim积)题解
题意:在一个二维平面中,有n个灯亮着并告诉你坐标,每回合需要找到一个矩形,这个矩形xy坐标最大的那个角落的点必须是亮着的灯,然后我们把四个角落的灯状态反转,不能操作为败
思路:二维Nim积,看不懂啊,只能套模板了
参考:HDU 3404 Switch lights (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 main(){
int T;
scanf("%d", &T);
int ans;
while(T--){
ans = ;
int n, x, y;
scanf("%d", &n);
while(n--){
scanf("%d%d", &x, &y);
ans ^= Nim_Mul(x, y);
}
if(ans)
printf("Have a try, lxhgww.\n");
else
printf("Don't waste your time.\n");
}
return ;
}
HDU 3404 Switch lights(Nim积)题解的更多相关文章
- HDU 3404&POJ 3533 Nim积(二维&三维)
(Nim积相关资料来自论文曹钦翔<从"k倍动态减法游戏"出发探究一类组合游戏问题>) 关于Nim积计算的两个函数流程: 代码实现如下: ][]={,,,}; int N ...
- HDU 3404 Switch lights 博弈论 nim积
http://acm.hdu.edu.cn/showproblem.php?pid=3404 题目 http://www.doc88.com/p-5098170314707.html 论文 nim积在 ...
- hdu 3404 Switch lights 博弈论
主要是求NIM积!!! 代码如下: #include<iostream> #include<cstdio> #include<stack> #include< ...
- POJ 3533 Light Switching Game(三维Nim积)题解
思路:三维Nim积 代码: #include<set> #include<map> #include<stack> #include<cmath> #i ...
- Nim积解法小结
由于某毒瘤出题人 redbag 不得不学习一下这个史诗毒瘤算法. 本文参考了 Owaski 的 GameTheory 的课件. 定义 我们对于一些二维 \(\mathrm{Nim}\) 游戏(好像更高 ...
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- POJ 3553 Light Switching Game 博弈论 nim积 sg函数
http://poj.org/problem?id=3533 变成三维的nim积..前面hdu那个算二维nim积的题的函数都不用改,多nim积一次就过了...longlong似乎不必要但是还是加上了 ...
- hdu3404 Switch lights
题目描述 题解: 首先,由$SG$定理得SG(x,y)=mex(SG(x',y)^SG(x,y')^SG(x',y'))(x'<x,y'<y) 这里的$SG(x,y)$叫$Nim$积. $ ...
- Nim积的一种???的写法
Nim积总不能一直打四次暴力吧! 用SG定理等东西,可以证明 \((N, \oplus, \otimes)\) 构成一个域.(证明很难,我不会) 其中 \(\oplus\) 为异或, \(x \oti ...
随机推荐
- sass的@at-root
一.首先理解sass的嵌套中 &表示是什么? &表示整个选择器,而不单个class属性值或id属性值或tagName.例如下面一段代码: .a { .b { & { color ...
- php表单身份验证
1. index.php <form method="post" action="dbtest.php"> 姓名: ...
- mysql 权限管理 revoke 回收权限 命令
回收所有库,所有表的所有权限 revoke all on *.* from 针对mike的账号 回收 所有库,所有表的select权限 mysql> revoke select on *.* f ...
- 实习培训——Servlet(7)
实习培训——Servlet(7) 1 Servlet 异常处理 当一个 Servlet 抛出一个异常时,Web 容器在使用了 exception-type 元素的 web.xml 中搜索与抛出异常类 ...
- python3内置函数大全(顺序排列)
python3内置函数大全 内置函数 (1)abs(), 绝对值或复数的模 1 print(abs(-6))#>>>>6 (2)all() 接受一个迭代器,如果迭代器的所有 ...
- weka数据挖掘拾遗(二)---- 特征选择(IG、chi-square)
一.说明 IG是information gain 的缩写,中文名称是信息增益,是选择特征的一个很有效的方法(特别是在使用svm分类时).这里不做详细介绍,有兴趣的可以googling一下. chi-s ...
- 20180531-Postman 常用测试结果验证及使用技巧
- [LeetCode] 122. Best Time to Buy and Sell Stock II_Easy tag: Dynamic Programming
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- Java-二分查找算法
package com.lym.binarySearch; import java.util.Arrays; /** * 二分查找 * * @author Administrator * */ pub ...
- python -- 解决If using all scalar values, you must pass an index问题
[问题描述] 在将dict转为DataFrame时会报错:If using all scalar values, you must pass an index 例如: summary = pd.Dat ...