题解 P3949 【答案错误】
Great_Influence · · 题解
迷之数论,证明比猜难。
首先,先猜一个结论:
证明很简单。首先,分组要求可以转化为
其中S为其中一组。
先观察样例,可以发现,
设
原式左边
分析这个式子,发现除了最后一项1以外,其他几项就是i-1的要求,于是可以直接复制第i-1项的关系,在将第i-1项的关系在复制一遍并都加上
设箭头表示2k+1和2k+2中的选择方向,
分析可以发现,若
代码:
#include<bits/stdc++.h>
#include<cctype>
#define For(i,a,b) for(i=(a),i##end=(b);i<=i##end;++i)
#define Forward(i,a,b) for(i=(a),i##end=(b);i>=i##end;--i)
#define Rep(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;++i)
#define Repe(i,a,b) for(register int i=(a),i##end=(b);i>=i##end;--i)
using namespace std;
template<typename T>inline void read(T &x){
T s=0,f=1;char k=getchar();
while(!isdigit(k)&&k^'-')k=getchar();
if(!isdigit(k)){f=-1;k=getchar();}
while(isdigit(k)){s=s*10+(k^48);k=getchar();}
x=s*f;
}
void file(void){
#ifndef ONLINE_JUDGE
freopen("water.in","r",stdin);
freopen("water.out","w",stdout);
#endif
}
static int n,q;
void work()
{
read(n);
read(q);
static long long k,j;
static bool is;
Rep(i,1,q)
{
read(k);j=1;is=k&1;k=(k+1)>>1;
while(j<=k)j<<=1;
while(k>1)
{
while(j>=k)j>>=1;
is^=1;k-=j;
}
printf("%c\n",is?'X':'Z');
}
}
int main(void){
file();
work();
return 0;
}
(题解比代码难打多了,题目想了10多min,题解打了将近30min。。。。。。)