aaaaaaaaaaA heH heH nuN
题意:
规定一个字符串芳香的前缀是nunhehheh,后缀是数量个的a;给定一个n ,找出有n个芳香子序列的字符串。
思路:
nunhehheh + a * x,有2^x - 1个有效子序列
nunhehhe hhhha ,有p个h,则有p个有效子序列
那么在最后一个a前面加一个h就可以构成2 ^ x个有效子串
例如 haha == 4 haaha == 8
直接对应到2进制,所以我们直接枚举有多少个二进制位有1,然后在最前面那个a后面加h和对应二进制位上加h(即a与a之间的空位)即可构造
AC代码:
#include <iostream>
#include <algorithm>
#include <bitset>
#include <string.h>
using namespace std;
int s[50];
void solve(){
int n;cin >> n;
bitset<33>q(n);
memset(s,0,sizeof s);
if(q.test(0)) s[1] ++;
for(int i = 1;i <= 31;i ++)
if(q.test(i)) s[i]++,s[1]++;
cout << "nunhehhe";
for(int i = 31;i > 0;i --){
for(int j = 0;j < s[i];j ++)
cout << "h";
cout << "a";
}
cout << endl;
return;
}
int main(){
int t;cin >> t;
while(t --){
solve();
}
return 0;
}