标签:
http://www.lydsy.com/JudgeOnline/problem.php?id=3576
SG函数
我们发现$\left \lfloor \frac{n}{i} \right \rfloor$只有$\sqrt{n}$个取值
不妨设$x=\left \lfloor \frac{n}{i} \right \rfloor$
那么最终的分割方案一定是下面4种情况之一:偶数个$x$,偶数个$x+1$;偶数个$x$,奇数个$x+1$;奇数个$x$,偶数个$x+1$;奇数个$x$,奇数个$x+1$。
分类讨论解不定方程即可。
如果判断偶数个$x$,奇数个$x+1$的方案是否存在就是问以下的不定方程有没有解:
$2k_1x+(2k_2+1)(x+1)=n$
$2k_1+2k_2+1\geq 2$
#include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<utility> #include<set> #include<bitset> #include<vector> #include<functional> #include<deque> #include<cctype> #include<climits> #include<complex> #include<cassert> //#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL; typedef double DB; typedef pair<int,int> PII; typedef pair<DB,DB> PDD; typedef complex<DB> CP; typedef vector<int> VI; #define mmst(a,v) memset(a,v,sizeof(a)) #define mmcy(a,b) memcpy(a,b,sizeof(a)) #define fill(a,l,r,v) fill(a+l,a+r+1,v) #define re(i,a,b) for(i=(a);i<=(b);i++) #define red(i,a,b) for(i=(a);i>=(b);i--) #define fi first #define se second #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define SF scanf #define PF printf #define two(k) (1<<(k)) #define SZ(x) (int(x.size())) #define all(x) (x).begin(),(x).end() #define ire(i,v,x) for(i=0,v=i<SZ(x)?x[i]:0;i<SZ(x);v=x[++i]) template<class T>inline T sqr(T x){return x*x;} template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;} template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} inline int sgn(DB x){if(abs(x)<1e-9)return 0;return(x>0)?1:-1;} const DB Pi=acos(-1.0); int gint() { int res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!=‘-‘ && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z==‘-‘){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-‘0‘,z=getchar()); return (neg)?-res:res; } LL gll() { LL res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!=‘-‘ && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z==‘-‘){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-‘0‘,z=getchar()); return (neg)?-res:res; } const int maxn=100100; const int maxm=110; int F; int n,SG[maxn]; int m,stone[maxm]; int ci,bak[maxn]; int check(int x,int n,int f) { if(n<0)return 0; if(n&1)return 0; n>>=1; if(!f) return (n+x+1-1)/(x+1)<=n/x; if(n%(x+1)==0 && n/(x+1)>=1)return 1; if(n%x==0 && n/x>=1)return 1; return (1+n+x+1-1)/(x+1)<=(n-1)/x; } int main() { freopen("game.in","r",stdin); freopen("game.out","w",stdout); int i,T=gint();F=gint(); while(n+1<F)SG[++n]=0; while(T--) { int n2=0; m=gint(); re(i,1,m)upmax(n2,stone[i]=gint()); while(n<n2) { n++;ci++; int x; for(i=2;i<=n;i=n/x+1) { x=n/i; if(check(x,n,1)) bak[0]=ci; if(check(x,n-x,1)) bak[SG[x]]=ci; if(check(x,n-x-1,1)) bak[SG[x+1]]=ci; if(check(x,n-x-x-1,0)) bak[SG[x]^SG[x+1]]=ci; } for(i=0;bak[i]==ci;i++); SG[n]=i; } int ans=0; re(i,1,m)ans^=SG[stone[i]]; PF("%d ",min(ans,1)); } return 0; }
标签:
原文地址:http://www.cnblogs.com/maijing/p/5252189.html