95pts求调
查看原帖
95pts求调
524450
yiduiiii楼主2023/11/12 11:57

最后一个点一直调不对

#include <iostream>
#include <cstdio>
#include <cmath>
#define LL unsigned long long
using namespace std;
LL k;
int n;

LL fastpow(int x)
{
	LL ans=1, a=2; 
	while (x)
	{
		if (x&1) ans*=a;
		a*=a;
		x>>=1;
	}
	return ans;
} 

void gray(int l, LL f)
{
	if (l==0) return;
	LL t=fastpow(l);
	t-=f-1;
	LL tt=fastpow(l-1);
	if (f>tt)
	{
		cout << 1;
		gray(l-1, t);
	}
	else 
	{
		cout << 0;
		gray(l-1, f);
	}
	//cout << (1<<l)  << "special" <<  endl;
}

int main ()
{
	scanf("%d %lld", &n, &k);
	//cout << k << endl;
	gray(n, k+1);
	//cout << (1<<44) << endl;
	return 0;
}

2023/11/12 11:57
加载中...