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. Educational Codeforces Round 54 (Rated for Div. 2) ABCD

    A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...

  2. 对zip文件进行解压操作和对一个文件进行压缩操作

    注意这里用的是apche下的zip package org.springframework.validation; import org.apache.tools.zip.ZipEntry; impo ...

  3. python 一些乱七八糟的东西

    import random import os import sys import re class _is: def __init__(self,reg): self.cr=re.compile(r ...

  4. oracle 数据库图形化工具 sqldeveloper

    1. 安装完成Oracle数据库,点击左下角[开始]菜单,在所有程序中打开[Oracle] 2. 在开始菜单,展开Oracle数据库,安装文件,然后打开[应用程序开发].可以看到[sqldevelop ...

  5. centos yum 安装 mysql

      centos7下使用yum安装mysql 时间:2015-03-07 21:26:20      阅读:87445      评论:0      收藏:1      [点我收藏+] 标签: Cen ...

  6. 转: 构建基于Nginx的文件服务器思路与实现

    在Web项目中使用独立的服务器来保存文件和图片的好处很多,如:便于统一管理,分流web服务器的压力,可进行访问加速等.另外当web服务器需要做集群进行负载均衡时,图片和文件上传在各个服务器之间同步将是 ...

  7. 【SPOJ-QTREE3】树链剖分

    http://www.spoj.com/problems/QTREE3/ 时间限制:2s    代码长度限制:50000B     内存限制:1536MB [题目描述] 给出N个点的一棵树(N-1条边 ...

  8. Linux 下面adb命令的使用

    平板或者android手机使用adb是非常方便的.接下来我就介绍下adb使用以及一些常用的命令. 1,连接 用adb连接线,一端接PC的USB中,一端接平板或手机的adb口,当然得确保线没有问题,而且 ...

  9. GridPanel分页条插件

    GridPanel的分页条没有设置当前页显示条数的功能,会不大方便 主要是抄袭的http://www.cnblogs.com/badwps/archive/2011/04/15/2016440.htm ...

  10. Python3 安装xlrd、xlwt、xlutils

    Python版本3.4,装xlrd和xlwt和xlutils的时间:2017-09-07. 安装xlrd.xlwt.xlutils很简单,直接[pip install xlrd].[pip insta ...