二进制凑数+路线规划构造题

妙啊妙啊
https://ac.nowcoder.com/acm/contest/92687/K

#include<bits/stdc++.h>
#define endl '\n'
#define lowbit(x) (x&-x)
using namespace std;
const double pi=acos(-1);
int pre[30];
void solve(){
    int n;cin>>n;
    vector<int> a(n+1);
    int mx=-1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
    }
    int cnt=0,t=1;
    while(t<=mx){
        t<<=1;cnt++;
    }
    
    t>>=1;
    cnt--;
    
    pre[0]=1;
    for(int i=1;i<=26;i++){
        pre[i]=pre[i-1]*2;
    }
    vector ans(cnt+2, vector<int>());
    for(int i=0;i<=cnt+1;i++){
        ans[i].resize(i+1, 0);
        ans[i][0]=0;
        for(int j=1;j<=i;j++){
            if(j%2==1) ans[i][j]=1;
            else ans[i][j]=0;
        }
    }
    cout<<cnt+2<<endl;
    for(int i=0;i<=cnt+1;i++){
        for(int j=0;j<=i;j++){
            if(ans[i][j]==0){
                cout<<0<<" ";
            }
            else cout<<pre[i-1]<<" ";
        }
        cout<<endl;
    }
    vector<string> anss;
    for(int i=1;i<=n;i++){
        int t=a[i];
        string ts;
        int pos=0;
        
        for(int j=0;j<cnt+1;j++){
            if((t>>j)&1){
                if(ans[j][pos]){
                    ts+="L";
                }
                else{
                    ts+="R";pos++;
                }
            }
            else{
                if(!ans[j][pos]){
                    ts+="L";
                }
                else{
                    ts+="R";pos++;
                }
            }
        }
        anss.emplace_back(ts);
    }
    for(int i=0;i<n;i++){
        cout<<anss[i]<<endl;
    }
}
signed main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}

posted on 2024-10-17 18:45  TaopiTTT  阅读(2)  评论(0编辑  收藏  举报