hdu 1210 Eddy's 洗牌问题

来源:互联网 发布:工程对接软件 编辑:程序博客网 时间:2024/05/20 07:16

题目链接:点击打开链接


模拟水题。

假设有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;}


0 0
原创粉丝点击