semipal.in / semipal.out

Por Costel the pig, our programmer in-training, has recently returned from the Petrozaporksk training camp. There, he learned a lot of things: how to boil a cob, how to scratch his belly using his keyboard, etc... He almost remembers a programming problem too:

A semipalindrome is a word  for which there exists a subword  such that  is a prefix of  and  (reverse ) is a suffix of . For example, 'ababba' is a semipalindrom because the subword 'ab' is prefix of 'ababba' and 'ba' is suffix of 'ababba'.

Let's consider only semipalindromes that contain letters 'a' and 'b'. You have to find the -th lexicographical semipalindrome of length .

Por Costel doesn't remember if the statement was exactly like this at Petrozaporksk, but he finds this problem interesting enough and needs your help to solve it.

Input

On the first line of the file semipal.in, there is an integer  () representing the number of test cases. On the next  lines there are 2 numbers,  ( and K  where  is the number of semipalindromes of length .

Output

In the output file semipal.out, there should be  lines, the -th of which should contain the answer for the -th test.

Example

Input
2
5 1
5 14
Output
aaaaa
bbabb

显然只需要保证开头和结尾字母相同,就一定是合法的啦。

然后就把中间的部分得到即可。

#include<cstdio>
using namespace std;
typedef long long ll;
int T,n;
ll m;
char a[70];
int main()
{
// freopen("l.in","r",stdin);
freopen("semipal.in","r",stdin);
freopen("semipal.out","w",stdout);
scanf("%d",&T);
for(;T;--T)
{
scanf("%d%I64d",&n,&m);
// ll all=1ll<<(n-1);
bool flag=0;
if(m>(1ll<<(n-2)))
{
m-=(1ll<<(n-2));
flag=1;
}
--m;
for(int i=1;i<=n-2;++i)
{
a[i]=(m%2 ? 'b' : 'a');
m/=2;
}
if(flag)
{
putchar('b');
for(int i=n-2;i>=1;--i)
putchar(a[i]);
puts("b");
}
else
{
putchar('a');
for(int i=n-2;i>=1;--i)
putchar(a[i]);
puts("a");
}
}
return 0;
}

【找规律】Gym - 100923L - Por Costel and the Semipalindromes的更多相关文章

  1. 【Heap-dijkstra】Gym - 100923B - Por Costel and the Algorithm

    algoritm.in / algoritm.out Even though he isn't a student of computer science, Por Costel the pig ha ...

  2. 【分块打表】Gym - 100923K - Por Costel and the Firecracker

    semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...

  3. 【数形结合】Gym - 100923I - Por Costel and the Pairs

    perechi3.in / perechi3.out We don't know how Por Costel the pig arrived at FMI's dance party. All we ...

  4. 【并查集】Gym - 100923H - Por Costel and the Match

    meciul.in / meciul.out Oberyn Martell and Gregor Clegane are dueling in a trial by combat. The fight ...

  5. 【动态规划】Gym - 100923A - Por Costel and Azerah

    azerah.in / azerah.out Por Costel the Pig has received a royal invitation to the palace of the Egg-E ...

  6. 【带权并查集】Gym - 100923H - Por Costel and the Match

    裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[10 ...

  7. Codeforces (ccpc-wannafly camp day2) L. Por Costel and the Semipalindromes

    题目链接:http://codeforces.com/gym/100923/problem/L 分析:题目要求序列首尾相同,在此基础上的字典序第k个:因为只存在a,b所以我们把它等效成0和1的话,字典 ...

  8. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  9. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

随机推荐

  1. VC++使用CImage PNG转BMP图片透明背景处理

    PNG格式的图片是支持透明通道的,BMP格式的图片是没有透明通道的,所以当PNG格式的图片转换为BMP格式时,对于PNG图片的透明背景就需要进行特别的处理. VC++中的HBITMAP是支持透明色的, ...

  2. 转:Linux 目录结构和常用命令

    转自:http://www.cnblogs.com/JCSU/articles/2770249.html仅为学习参考之用 一.Linux目录结构 你想知道为什么某些程序位于/bin下,或者/sbin, ...

  3. openstack 问题澄清

    1. neutron中plugin与agent是一一对应的吗? 在不使用ml2时,plugin与agent一一对应,如ovs-plugin与ovs-agent:当使用ml2 plugin时,该plug ...

  4. bzoj 1045糖果传递 数学贪心

    首先我们假设平均数为ave 那么对于第1个人,我们假设他给第N个人K个糖果,第2个人给1,第3个人给2,第n个人给第n-1个人 那么对于第1个人给完n,第2个人给完1,第一个人不会再改变糖果数了,所以 ...

  5. python判断操作系统

    https://www.crifan.com/python_get_current_system_os_type_and_version_info/ 参考:https://stackoverflow. ...

  6. ZOJ 3598 Spherical Triangle球面几何公式应用

    #include <map> #include <set> #include <list> #include <cmath> #include < ...

  7. UVA 10183 How Many Fibs?

    高精度推出大概600项fabi数,就包含了题目的数据范围,对于每组a,b,从1到600枚举res[i]即可 可以直接JAVA大数.我自己时套了C++高精度的版 JAVA 复制别人的 import ja ...

  8. mininet+floodlight搭建sdn环境并创建简单topo

    第一步:安装git sudo apt-get update sudo apt-get install git 测试git是否安装成功: git 第二步:安装mininet 1.获取mininet最新源 ...

  9. String类的常见方法的使用案例

    String类的常见方法的使用案例 //使用指定的字符串替换当前字符串中指定的内容 //将helloworld中的o替换为a String s="HelloWorld"; Stri ...

  10. 串口通讯超时的设置与含义(COMMTIMEOUTS)

    COMMTIMEOUTS:COMMTIMEOUTS主要用于串口超时参数设置.COMMTIMEOUTS结构如下: typedef struct _COMMTIMEOUTS { DWORD ReadInt ...