NBUT 1225 NEW RDSP MODE I

时间:2022-04-19 10:18:20

找出循环周期即可了

#include<bits/stdc++.h>
using namespace std;
int N,M,X;
int time(int x,int y,int z)
{
if(z!=0&&x==1)
return z;
if(x%2==0)
x/=2;
else
x=(x+y+1)/2;
return time(x,y,z+1);
}
int operate(int x)
{
if(x<=N/2)
return x*2;
else
return (x-N/2)*2-1;
}
int main()
{
while(scanf("%d%d%d",&N,&M,&X)==3)
{
M%=time(1,N,0);
for(int i=1;i<=X;i++)
{
if(i!=1)
printf(" ");
int ans=i;
for(int j=1;j<=M;j++)
ans=operate(ans);
printf("%d",ans);
}
printf("\n");
}
return 0;
}