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 ...
随机推荐
- ubuntu 下关闭apache服务自动启动
最近在自己的ubuntu安装了apache服务器,每次开机的时候通过: ps -A 命令发现apache服务总是自动启动,如下: 本来自己的电脑内存就小,现在也不用这个服务,所以想让apa ...
- EControl平台测试向生产版本工程切换说明
第一步,备份生产环境版本,假设生产环境版本工程名为SEHEControl,记录版本说明第二部,拷贝测试版本到新文件夹,假设测试版本工程名为SEHEControlTest第三步,进入工程文件夹,修改SL ...
- 交换机-查看mac地址表
1.使用交换机命令行 en 或者 enable 进入特权模式 Switch> Switch>en Switch# Switch# 2.查看交换机中的MAC地址表 Switch#sh ...
- 在centos7下安装svn
SVN的安装 yum install subversion 服务端命令 1. svnserver - 控制svn系统服务的启动等 2. svnadmin - 版本库的创建/导出/导入/删除等 3. s ...
- [django]JsonResponse序列化数据
def home(request): data = { 'name': 'maotai', 'age': 22 } import json return HttpResponse(json.dumps ...
- JSP表单提交与接收
JSP表单提交与接收 在Myeclipse中新建web project,在webroot中新建userRegist1.jsp,代码如下 <%@ page contentType="te ...
- 在django项目中使用django-ckeditor
安装django-ckeditor pip install django-ckeditor 安装Pillow Pillow是python的一个图像处理库,django-ckeditor需要依赖该库.最 ...
- 什么时候block 是放在全局区里面的?
When a Block literal is written where there are global variables When the syntax in a Block literal ...
- leetcode & lintcode 题解
刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...
- Postman + newman + jenkins 的API自动化测试应用
一.环境配置 Postman postman 的具体使用可以参考另外一篇文章:postman 做接口测试之学习笔记 Newman 第一步,安装nodejs. 第二步,在nodejs命令行安装newma ...