主题思想: 找规律
跟踪第一张牌的位置,如果第一张牌回到了起点,则整体到了初始顺序。
对于第i张牌
if(i>n) 找规律发现,n+1,n+2,n+3其位置为1,3,5, =2*(i-n)-1
else i=2*i
AC代码
#include <iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n;
int handle(){
int x=2;
int ans=1;
while(x!=1){
if(x>n){
x=(x-n)*2-1;
}else{
x=x*2;
}
ans++;
}
return ans;
}
int main()
{
int ans=0;
while(scanf("%d",&n)!=EOF){
ans=handle();
printf("%d\n",ans);
}
return 0;
}