zoukankan      html  css  js  c++  java
  • 【找规律】Gym

    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;
    }
  • 相关阅读:
    windos端zabbix_agent重启报错:cannot open service
    搭建git服务器:centos环境
    git常用命令
    Centos7下ifconfig command not found 解决办法
    如何将EPEl安装在Centos7上
    linux安装openoffice,并解决中文乱码
    docker上配置mysql主从复制
    在docker上部署mysql
    linux上创建svn服务器(centos7.3)
    微信开发基于springboot
  • 原文地址:https://www.cnblogs.com/autsky-jadek/p/6321749.html
Copyright © 2011-2022 走看看