暴力求优化,蒟蒻求助QWQ
  • 板块灌水区
  • 楼主___LOSER___
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/7/10 14:44
  • 上次更新2023/11/3 10:45:33
查看原帖
暴力求优化,蒟蒻求助QWQ
616028
___LOSER___楼主2023/7/10 14:44

https://www.luogu.com.cn/discuss/lists?forumname=P5657

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int Max=1e8;
int a[Max],b[Max];
long long n,k,r,p=0,l;
int t,y;
bool flag=false;
void turn2()
{
    for(int i=1; ; i++){
        p++;
        b[i]=a[y]%2;
        a[y]/=2;
        if(a[y]==0)    break;
    }
    if(p==l){
        for(int j=p; j>=1; j--){
            cout<<b[j]; 
        }   
    }
    else {
        for(int j=n; j>p; j--){
            cout<<'0';  
        } 
        for(int j=p; j>=1; j--){
            cout<<b[j]; 
        }
    }
}
void yic()
{
    a[1]=0;
    a[2]=1;
    t=1;
    y=k+1;
    l=n;
    if(n==1)  {
        cout<<a[y];
    }  
    else{
        while(t<=(n-1)){
            r=powl(2,t);
            int o=1;
            for(int i=r; i>=1; i--){
                a[r+o]=a[i]+r;
                if(r+o==y)  {
                    flag=true;
                    break;  
                }
                o++;
            }
            t++;
            if(flag==true){
                break;  
            }
        }
        turn2();
    }

}

int main()
{
    //freopen("code.in","r",stdin);
    //freopen("code.out","w",stdout);
    cin>>n>>k;
    yic();
    return 0;
  }
2023/7/10 14:44
加载中...