I - Infinite Improbability Drive

I - Infinite Improbability Drive
http://codeforces.com/gym/241750/problem/I
不断构造,先填n-1个0,然后能放1就放1,最后这个序列的长度就是(1<<n)+n-1,也就是每添加1位就要匹配出来一个。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<set>
 8 #include<map>
 9 #include<stack>
10 #include<cstring>
11 #define inf 2147483647
12 #define ls rt<<1
13 #define rs rt<<1|1
14 #define lson ls,nl,mid,l,r
15 #define rson rs,mid+1,nr,l,r
16 #define N 100010
17 #define For(i,a,b) for(int i=a;i<=b;i++)
18 #define p(a) putchar(a)
19 #define g() getchar()
20 
21 using namespace std;
22 int n;
23 int a[10000000];
24 bool vis[10000000];
25 int ans,t,fin;
26 
27 void in(int &x){
28     int y=1;
29     char c=g();x=0;
30     while(c<'0'||c>'9'){
31         if(c=='-')y=-1;
32         c=g();
33     }
34     while(c<='9'&&c>='0'){
35         x=(x<<1)+(x<<3)+c-'0';c=g();
36     }
37     x*=y;
38 }
39 void o(int x){
40     if(x<0){
41         p('-');
42         x=-x;
43     }
44     if(x>9)o(x/10);
45     p(x%10+'0');
46 }
47 int main(){
48     freopen("infinite.in","r",stdin);
49     freopen("infinite.out","w",stdout);
50     in(n);
51     fin=(1<<n)+n-1;
52     a[n]=1;
53     vis[1]=1;
54     For(i,n+1,fin){
55         a[i]=1;
56         t=1;
57         ans=0;
58         for(int j=i;j>=i-n+1;j--){
59             ans+=t*a[j];
60             t<<=1;
61         }
62         if(vis[ans]){
63             vis[ans-1]=1;
64             a[i]=0;
65         }
66         else
67             vis[ans]=1;
68     }
69     For(i,1,fin)
70         o(a[i]);
71     return 0;
72         
73 }
View Code

猜你喜欢

转载自www.cnblogs.com/war1111/p/10659155.html
今日推荐