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

妙啊妙啊
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   TaopiTTT  阅读(3)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示