您的位置:首页 > 其它

hdu 1210 Eddy's 洗牌问题

2014-08-23 23:15 337 查看
题目链接:点击打开链接

模拟水题。

假设有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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: