HDU 1210 Eddy's 洗牌问题 数论
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1210
只需要判断1的走向就行,当回到1时就回到原样了。
代码如下:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <vector>#include <list>#include <deque>#include <queue>#include <iterator>#include <stack>#include <map>#include <set>#include <algorithm>#include <cctype>using namespace std;const int N=2011;typedef long long LL;int main(){ int i,j,n; while(cin>>n) { int t=1,i=0; do { if(t<=n) t*=2; else t=(t*2-1)%(2*n); i++; }while(t!=1); cout<<i<<endl; } return 0;}