题目描述

题解:

首先,由$SG$定理得SG(x,y)=mex(SG(x',y)^SG(x,y')^SG(x',y'))(x'<x,y'<y)

这里的$SG(x,y)$叫$Nim$积。

$Nim$积满足交换律、结合律以及对$Nim$和(异或)的分配律。

代码:

#include<cstdio>
#include<cstring>
int T,n;
int mp[][];
int nim_mul(int x,int y)
{
if(x<y)x^=y^=x^=y;
if(x<=&&~mp[x][y])return mp[x][y];
if(!y)return mp[x][y]=;
if(x==)return mp[x][y]=;
int t = ;
while(t*t<=x)t=t*t;
int c1 = nim_mul(x/t,y/t);
int c2 = nim_mul(x/t,y%t)^nim_mul(x%t,y/t);
int c3 = nim_mul(x%t,y%t);
int ret = (c1^c2)*t^c3^nim_mul(t/,c1);
if(x<=)mp[x][y]=ret;
return ret;
}
int main()
{
scanf("%d",&T);
memset(mp,-,sizeof(mp));
while(T--)
{
int ans = ;
scanf("%d",&n);
while(n--)
{
int x,y;
scanf("%d%d",&x,&y);
ans^=nim_mul(x,y);
}
puts(ans?"Have a try, lxhgww.":"Don't waste your time.");
}
return ;
}

hdu3404 Switch lights的更多相关文章

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

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

  2. HDU 3404 Switch lights 博弈论 nim积

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

  3. hdu 3404 Switch lights 博弈论

    主要是求NIM积!!! 代码如下: #include<iostream> #include<cstdio> #include<stack> #include< ...

  4. Nim积解法小结

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

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

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

  6. codeforces 877e

    E. Danil and a Part-time Job time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Codeforces Round #442 (Div. 2)A,B,C,D,E(STL,dp,贪心,bfs,dfs序+线段树)

    A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  8. CodeForces 877E Danil and a Part-time Job(dfs序+线段树)

    Danil decided to earn some money, so he had found a part-time job. The interview have went well, so ...

  9. Codeforces Round #877 (Div. 2) E. Danil and a Part-time Job

    E. Danil and a Part-time Job 题目链接:http://codeforces.com/contest/877/problem/E time limit per test2 s ...

随机推荐

  1. E20180327-hm

    renew vt. 补充; 重新开始; 使更新; 使恢复; vi. 重申,重复强调; 重新开始; renewal  n. 重建,重生; 更新,革新; 重申; 合同的续订;

  2. 【杂谈】5G有啥用?跟咱有关系么?关注那玩意儿干啥?

    用处大了 有啥用? 云计算啊,你看看你电脑都卡成啥了? 既然5G速度赶上本地读取,那就相当于把硬盘放云端没问题了.那么,看看自己硬盘里都有啥,5G的用处或许就能一点点浮现出来了. ——请不要急着打开一 ...

  3. 自定义层or网络

    目录 Outline keras.Sequential Layer/Model MyDense MyModel Outline keras.Sequential keras.layers.Layer ...

  4. LuoguP1370 Charlie的云笔记序列 【dp】By cellur925

    题目传送门 题目大意:给你一个序列,求出它所有区间的本质不同的子序列个数.(空序列也算作本质不同),数据范围$1e5$. 我们肯定是不能一个个枚举区间的...而且这个复杂度下,也就大概$O(n)$或$ ...

  5. (四)SpringBoot如何定义消息转换器

    一:添加fastjson依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastj ...

  6. HTML5移动端手机网站开发流程

    基本上开发手机网站,可大致分为两大类.一类是用框架开发手机网站.一类是自己手写手机网站. 一.框架开发手机网站 一般用现在常用的开发框架有:目前Web前端最火的框架(BootStrap).jQuery ...

  7. websocket实现单聊

    server# @File: ws from flask import Flask, request, render_template from geventwebsocket.handler imp ...

  8. JSP与Servlet的编解码

    一.java web中涉及编解码的地方 (1)浏览器端向后台发起请求时:URL.Cookie.Parameter: (2)后台响应返回数据时:页面编码,数据库数据编码:

  9. iOS UILabel UITextView自适应文本,或文本大小自适应

    //UILabel自适应文本的高度 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; label.numberOf ...

  10. 74LVC2G241双缓冲3态驱动器