【找规律】Gym - 100923L - Por Costel and the Semipalindromes
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
2
5 1
5 14
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的更多相关文章
- 【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 ...
- 【分块打表】Gym - 100923K - Por Costel and the Firecracker
semipal.in / semipal.out Por Costel the pig, our programmer in-training, has recently returned from ...
- 【数形结合】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 ...
- 【并查集】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 ...
- 【动态规划】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 ...
- 【带权并查集】Gym - 100923H - Por Costel and the Match
裸题. 看之前的模版讲解吧,这里不再赘述了. #include<cstdio> #include<cstring> using namespace std; int fa[10 ...
- Codeforces (ccpc-wannafly camp day2) L. Por Costel and the Semipalindromes
题目链接:http://codeforces.com/gym/100923/problem/L 分析:题目要求序列首尾相同,在此基础上的字典序第k个:因为只存在a,b所以我们把它等效成0和1的话,字典 ...
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- codeforces Gym 100418D BOPC 打表找规律,求逆元
BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
随机推荐
- 使用setTimeout延时10ms执行onunloadcancel
在做Web开发时,我们经常用到页面关闭事件onbeforeunload,可以给用户一个选择放弃关闭的机会,就比如这个博客编辑器.如果用户选择了离开,那么onunload事件自然会触发:但若用户选择了取 ...
- fresco的使用教程
1.加载依赖 api 'org.xutils:xutils:3.5.0' 2.创建一个myapplication public class MyApplication extends Applicat ...
- Unable to start activity ComponentInfo{com.example.administrator.myapplication/com.example.administrator.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XM
本来就是把fragment写死在activity的xml模板里面,结果报了这个错误, Unable to start activity ComponentInfo{com.example.admini ...
- maven在add dependecy时搜索不出jar包的解决办法
一:前言 其实我一直都很头疼maven的项目管理的,因为觉得用起来还是没有那么方便的啊,不过今天我自己算是小弄了下maven项目的故那里,是一个同事在配置maven的项目,我去凑了下热闹而已,现在自己 ...
- Html 让文字显示在图片的上面
如题: 第一种方式便是将 image 作为背景图片,即:background-image:url("......."); 在此可以控制背景图片的横向和纵向的平铺: backgrou ...
- loadView不需要调用super view,原因:loadView方法的作用就是自定义view.[super loadView]会耗性能.
https://www.evernote.com/shard/s227/sh/423fd81d-ab1c-4e6c-997d-39359472a4a5/f220ade8bd9be149ad70 ...
- 小白科普之JavaScript的DOM模型
微信公众号“前端大全”推送了一篇名为“通俗易懂的来讲讲DOM”的文章,把javascript原生DOM相关内容讲解的很详细.仔细读了一遍,觉得整理总结的不错,对自己也很使用,所以把内容整理过来,并根据 ...
- algorithm ch6 heapsort
堆排序利用的是堆这种数据结构来对进行排序,(二叉)堆可以被视为一棵完全的二叉树,树的每个节点与数组中存放该节点的值得那个元素对应.这里使用最大堆进行排序算法设计,最大堆就是parent(i) > ...
- KVM的ept机制
转载:http://ytliu.info/blog/2014/11/24/shi-shang-zui-xiang-xi-de-kvm-mmu-pagejie-gou-he-yong-fa-jie-xi ...
- GUI自动化模块化实现方式
效率为王:脚本与数据的解耦 + Page Object模型 1.数据驱动:实现了“测试脚本和数据的解耦”,数据驱动测试的数据文件中不仅可以包含测试输入数据,还可以包含测试验证结果数据,甚至可以包含测试 ...