首页 > 代码库 > BZOJ 1411 ZJOI2009 硬币游戏

BZOJ 1411 ZJOI2009 硬币游戏

 递推;

技术分享
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 #define ll long long
 6 #define FILE "dealing"
 7 #define up(i,j,n) for(int i=j;i<=n;i++)
 8 #define db long double 
 9 #define pii pair<int,int>
10 #define pb push_back
11 #define mem(a,L) memset(a,0,sizeof(int)*(L+1))
12 template<class T> inline bool cmin(T& a,T b){return a>b?a=b,true:false;}
13 template<class T> inline bool cmax(T& a,T b){return a<b?a=b,true:false;}
14 template<class T> inline T squ(T a){return a*a;}
15 const int maxn=210000+10,inf=1e9+10,mod=10003;
16 ll read(){
17     ll x=0,f=1,ch=getchar();
18     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
19     while(ch>=0&&ch<=9)x=(x<<1)+(x<<3)+ch-0,ch=getchar();
20     return x*f;
21 }
22 ll n;
23 ll T,f;
24 ll a[maxn],b[maxn];
25 int main(){
26     freopen(FILE".in","r",stdin);
27     freopen(FILE".out","w",stdout);
28     n=read(),T=read();
29     up(i,0,n-1)a[i]=(read()+1)%2;
30     for(int i=1;i<=60;i++)
31         if(T&(1LL<<i)){
32             memcpy(b,a,sizeof(ll)*(n+1));
33             for(int j=0;j<n;j++)
34                 a[j]=b[(j-(1LL<<i-1)%n+n)%n]^b[(j+(1LL<<i-1))%n];
35         }
36     if(T&1){
37         memcpy(b,a,sizeof(ll)*(n+1));
38         for(int j=0;j<n;j++)
39             a[j]=b[j%n]^b[(j+1)%n];
40     }
41     if(T&1)up(i,0,n-1)printf("0 %lld%c",(a[i]+1),i==n-1?\n: );
42     else up(i,0,n-1)printf("%lld 0%c",(a[i]+1),i==n-1?\n: );
43     return 0;
44 }
View Code

 

BZOJ 1411 ZJOI2009 硬币游戏