开始还没想到居然,囧!
先老老实实的转换,再把串复制一遍
为什么要复制一遍?
仔细想一想旋转(也就是移位)的过程,
是不是和把串复制一遍然后枚举从 i 开始的前 N 个的情况?
是的话就对了,然后其他的就体现在代码里了。
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef unsigned long long int ULL;
#define BUG puts("HERE!")
using namespace std;
const int MAX = 1e2 + 5;
ULL t, n, m;
string s;
ULL a[MAX];
void ch2b(ULL m){
s.clear();
while (m && s.length() < n){
s += (m & 1) + '0';
m >>= 1;
}
int len = s.length();
for (int i = len; i < n; ++i){
s += '0';
}
reverse(s.begin(), s.end());
s += s;
}
ULL ch2d(int p){
ULL ans = 0, M = 1;
for(int i = p + n - 1; i >= p; i--){
if(s[i] == '1')
ans += M;
M <<= 1;
}
return ans;
}
int main(int argc, char const *argv[]){
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
#endif
cin >> t;
while (t --){
cin >> m >> n;
ch2b(m);
int p = 0;
int len = s.length() / 2;
for (int i = 0; i < n; ++i){
a[i] = ch2d(i);
}
sort(a, a + n);
for(int i = p; i < n; ++i)
cout << (a[i] & 1);
cout << endl;
}
return 0;
}