题目链接:点击打开链接
模拟水题。
假设有n张牌,令half=n/2 , 若牌的位置p<=half 牌的位置会变为p*2,若大于half则变为(p-half)*2-1。
代码:
#include <iostream>
#include <cstdio>
using namespace std;
int solve(int n){
int cur=2;
int half=n/2;
int res=1;
while(cur!=1){
if(cur<=half) cur*=2;
else cur=(cur-half)*2-1;
res++;
}
return res;
}
int main(){
int n;
while(cin>>n){
cout<<solve(n*2)<<endl;
}
return 0;
}