求该代码,蒟蒻飞舞
查看原帖
求该代码,蒟蒻飞舞
616028
___LOSER___楼主2023/7/10 09:00

超时最后四个点,蒟蒻不信邪请求大佬指点

#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();
    retu
2023/7/10 09:00
加载中...