📄 4571448_ce.cpp
字号:
#include<iostream>
#include<algorithm>
using namespace std;
struct biao
{
__int64 big;
__int64 small;
};
bool small=true;
bool big=false;
biao x[21][21];
bool used[21];
int test_number;
int n;
__int64 c;
int outnumber;
void tianbiao()
{
int m,n;
x[1][1].big=1;
x[1][1].small=1;
x[2][1].big=0;
x[2][1].small=1;
x[2][2].big=1;
x[2][2].small=0;
for(m=3;m<=21;m++)
{
for(n=1;n<=m;n++)
{
x[m][n].big=0;
for(int i=1;i<=n-1;i++)
{
x[m][n].big+=x[m-1][i].small;
}
x[m][n].small=0;
for(int j=n;j<=m-1;j++)
{
x[m][n].small+=x[m-1][j].big;
}
}
}
}
void out(int number)
{
int temp=0;
outnumber++;
for(int count=1;count<=n;count++)
{
if(used[count]==false) temp++;
if(temp==number)
{
cout<<count;
if(outnumber!=n) cout<<" ";
used[count]=true;
return;
}
}
}
void gets(int n,__int64 c,int now,bool type)
{
__int64 temp=0;
if(n==1) {out(1);return;}
if(type==small)
{
for(int i=1;i<=now-1;i++)
{
temp+=x[n][i].small;
if(temp>=c) {out(i);gets(n-1,c-temp,i,big);return;}
}
}
else
{
for(int j=now;j<=n;j++)
{
temp+=x[n][j].big;
if(temp>=c) {out(j);gets(n-1,c-temp,j,small);return;}
}
}
}
void get(int n,__int64 c)
{
__int64 temp=0;
if(n==1) {out(1);return;}
for(int count=1;count<=n;count++)
{
temp+=x[n][count].big;
if(temp>=c) {out(count);gets(n-1,c-temp,count,small);return;}
temp+=x[n][count].small;
if(temp>=c) {out(count);gets(n-1,c-temp,count,big);return;}
}
cout<<"get worng";
}
void main()
{
cin>>test_number;
tianbiao();
for(int count=0;count<test_number;count++)
{
if(count!=0) cout<<endl;
scanf("%d %i64d",&n,&c);
memset(used,false,sizeof(used));
outnumber=0;
get(n,c);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -