http://acm.cs.ecnu.edu.cn/problem.php?problemid=1444
约瑟夫环问题
找规律:
1 1 1...1
2 1 10...1
3 3 11...1
4 1 100...1
5 3 101...1
6 5 110...1
7 7 111...1
8 1 1000...1
左移一位
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <queue> 7 #include <stack> 8 #include <vector> 9 #include <string> 10 #include <set> 11 #include <cctype> 12 #include <cstdlib> 13 #include <map> 14 #define maxn 1000100 15 #define inf 0x3f3f3f3f 16 #define mod 9997 17 #define pi 3.1415926535898 18 #define LL long long 19 using namespace std; 20 21 int a[30]; 22 23 int main(){ 24 string s; 25 while (cin >> s){ 26 if (s == "00e0") break; 27 int t = (s[0] - '0') * 10 + s[1] - '0'; 28 int tmp = s[3] - '0'; 29 while (tmp--) 30 t *= 10; 31 32 int k = 1; 33 a[0] = 1; 34 while (t){ 35 a[k++] = t%2; 36 t /= 2; 37 } 38 for (int i = k - 2; i >= 0; i--) 39 t = t * 2 + a[i]; 40 cout << t << endl; 41 } 42 return 0; 43 }