社区讨论
80分WA,求助5555
P5657[CSP-S 2019] 格雷码参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lobacdtz
- 此快照首次捕获于
- 2023/10/29 17:45 2 年前
- 此快照最后确认于
- 2023/11/03 23:42 2 年前
CPP
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
long long n,m,k;
string ss;
string gl(int n,int now,string s)
{if(n==0) return s;
else if(n==1)
{if(now==1) return s+"0";
else if(now==2) return s+"1";
}
else if(n>1)
{if(now>pow(2,n-1))
{if(now<=3*pow(2,n-2))
{now=now+2*(3*pow(2,n-2)-now)+1;
return gl(n-1,now-pow(2,n-1),s+"1");
}
else if(now>3*pow(2,n-2))
{now=now-2*(now-3*pow(2,n-2))+1;
return gl(n-1,now-pow(2,n-1),s+"1");
}
}
else if(now<=pow(2,n-1)) return gl(n-1,now,s+"0");
}
return s;
}
int main()
{//cout<<ss<<"\n";
scanf("%lld%lld",&n,&k);
ss=gl(n,k+1,ss);
cout<<ss;
return 0;
}
样例三就会全爆0,提交是80分,这是为什么呀
回复
共 1 条回复,欢迎继续交流。
正在加载回复...