\(Description\)

\(n\)堆石子,每堆石子有\(s_i\)个,两个人轮流操作,每次可以将一对不少于\(F\)的石子尽量平均分成\(m\)堆,\(m\)每次自选,不能操作者输.共有\(T\)组数据

\(Solution\)

\(70\ pts\)

直接\(SG\)搞一搞就好了,枚举堆的个数,异或一下就没了

\(Code\)

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
int sg[100010],mex[100010],f,T;
int SG(int x){
if(sg[x]!=-1) return sg[x];
if(x<f) return sg[x]=0;
sg[x]=0;
for(int i=2;i<=x;i++){
int res=0,p=i-x%i,pp=x%i,c;
if(pp&1) c=SG(x/i+1),res^=c;
if(p&1) c=SG(x/i),res^=c;
mex[res]=x;
}
while(mex[sg[x]]==x)
sg[x]++;
return sg[x];
}
main(){
T=read(),f=read();
memset(sg,-1,sizeof(sg));
while(T--){
int n=read(),ans=0,x;
for(int i=1;i<=n;i++)
x=read(),ans^=SG(x);
printf("%d ",ans?1:0);
}
}

\(100\ pts\)

假设现在求的是\(x\)的\(sg\)值,我们动笔算一算,发现他每次求的都是:

\[\lfloor \frac{x}{i} \rfloor,\lfloor \frac{x}{i+1} \rfloor,\lfloor \frac{x}{i+2} \rfloor,\lfloor \frac{x}{i+3} \rfloor...
\]

但是这里面会有很多相等的答案,这个学过整除分块的应该都知道吧.

如果没学过就去看一看,很好理解.

所以对于每一个相同的答案只要计算\(i\)和\(i+1\)就好了

\(Code\)

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
int sg[100010],mex[100010],f,T;
int SG(int x){
if(sg[x]!=-1) return sg[x];
if(x<f) return sg[x]=0;
sg[x]=0;
for(int j=2;j<=x;j=x/(x/j)+1)
for(int i=j;i<=min(j+1,x);i++){
int res=0,p=i-x%i,pp=x%i;
if(pp&1) res^=SG(x/i+1);
if(p&1) res^=SG(x/i);
mex[res]=x;
}
while(mex[sg[x]]==x)
sg[x]++;
return sg[x];
}
main(){
T=read(),f=read();
memset(sg,-1,sizeof(sg));
while(T--){
int n=read(),ans=0,x;
for(int i=1;i<=n;i++)
x=read(),ans^=SG(x);
printf("%d ",ans?1:0);
}
}

「HNOI 2014」 江南乐的更多相关文章

  1. 「HNOI 2014」 画框

    题目链接 戳我 \(Solution\) 这一题很像最小乘积生成树.只是把\(kruskal\)变为了\(km\)/费用流 现在来讲一讲最小乘积生成树.首先将\(\sum a_i\)和\(\sum b ...

  2. 「HNOI 2014」米特运输

    题目链接 戳我 \(Describe\) 谁出的题目啊?这么长的题面,看完就滚粗了.强烈谴责 给一棵树,每个点有一个权值,要求修改一些权值,使: 一个点的权值必须是其所有儿子的权值之和 一个点的儿子权 ...

  3. 【LOJ】#2210. 「HNOI2014」江南乐

    LOJ#2210. 「HNOI2014」江南乐 感觉是要推sg函数 发现\(\lfloor \frac{N}{i}\rfloor\)只有\(O(\sqrt{N})\)种取值 考虑把这些取值都拿出来,能 ...

  4. LOJ#3054. 「HNOI 2019」鱼

    LOJ#3054. 「HNOI 2019」鱼 https://loj.ac/problem/3054 题意 平面上有n个点,问能组成几个六个点的鱼.(n<=1000) 分析 鱼题,劲啊. 容易想 ...

  5. 「HNOI 2019」白兔之舞

    一道清真的数论题 LOJ #3058 Luogu P5293 题解 考虑$ n=1$的时候怎么做 设$ s$为转移的方案数 设答案多项式为$\sum\limits_{i=0}^L (sx)^i\bin ...

  6. 「HNOI 2016」 序列

    \(Description\) 给你一个序列,每次询问一个区间,求其所有子区间的最小值之和 \(Solution\) 这里要用莫队算法 首先令\(val\)数组为原序列 我们考虑怎么由一个区间\([l ...

  7. 「HNOI 2015」实验比较

    \(Description\) 有\(n\)个元素,对于每个元素\(x_i\)最多知道一个形如\(x_j < x_i\)或\(x_j=x_i\)的条件,问有多少合法的序列.合法的序列满足每个元素 ...

  8. 「HNOI 2015」亚瑟王

    \(Description\) 有\(n\)张卡牌,每一张卡牌有\(p_i\)的概率发动,并造成\(d_i\)点伤害.一共有\(r\)轮,每一轮按照编号从小到大依次考虑,如果这张牌已经发动过则跳过该牌 ...

  9. 「HNOI 2015」菜肴制作

    题目链接 戳我 \(Description\) 有若干限制,需要求一个\(1\)到\(n\)的排列,每个限制\((x,y)\)表示\(x\)必须在\(j\)之前,并要求所求的排列满足所有限制并让\(1 ...

随机推荐

  1. Cookie&Session会话跟踪技术

    今日内容学习目标 可以响应给浏览器Cookie信息[response.addCookie()] 可以接受浏览器Cookie信息[request.getCookies()] [创建cookie,设置pa ...

  2. Python常见字符串处理操作

    Python中字符串处理的方法已经超过37种了,下面是一些常用的字符串处理的方法,以后慢慢添加. >>> s = 'Django is cool' #创建一个字符串 >> ...

  3. GameObject.Active

    [GameObject.Active] 用于控制一个对象是否激活,一个对象激活当且本身active=true,并且它的父结点也都active.相当API有: 1)GameObject.SetActiv ...

  4. Linux重启mysql Error getting authority: Error initializing authority: Could not connect: Resource temporarily unavailable (g-io-error-quark, 27)

    问题: Linux下重启mysql: systemctl restart mysqld 出现以下错误: Error getting authority: Error initializing auth ...

  5. unity3d 事件说明

    Unity3D中所有控制脚本的基类MonoBehaviour有一些虚函数用于绘制中事件的回调,也可以直接理解为事件函数,例如大家都很清楚的Start,Update等函数,以下做个总结.   Awake ...

  6. IDEA04 工具窗口管理、各种跳转、高效定位、行操作、列操作、live template、postfix、alt enter、重构、git使用

    1 工具窗口管理 所有的窗口都是在view -> tools windows 下面的,这些窗口可以放在IDEA的上下左右各个位置:右键某个窗口后选择move to 即可进行位置调整 2 跳转 2 ...

  7. 297. Serialize and Deserialize Binary Tree二叉树的序列化和反序列化(就用Q)

    [抄题]: Serialization is the process of converting a data structure or object into a sequence of bits ...

  8. Tomcat内存溢出及大小调整

    一.在使用Java程序从数据库中查询大量的数据或是应用服务器(如tomcat.jboss,weblogic)加载jar包时会出现java.lang.OutOfMemoryError异常.这主要是由于应 ...

  9. ros console_bridge找不到

    Could not find a package configuration file provided by "console_bridge" with any of the f ...

  10. [JAVA] 冻结Excel的第一行或第一列

    可以按照如下设置创建冻结窗口. sheet.createFreezePane( 3, 2, 3, 2 ); 前两个参数是你要用来拆分的列数和行数.后两个参数是下面窗口的可见象限,其中第三个参数是右边区 ...