ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #735 (Div. 2) D. Diane

2021-07-30 01:32:55  阅读:194  来源: 互联网

标签:string Diane 序列 735 each test such Div occurs


D. Diane time limit per test  :  1 second memory limit per test  :  256 megabytes

You are given an integer nn. Find any string ss of length nn consisting only of English lowercase letters such that each non-empty substring of ss occurs in ss an odd number of times. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Input

The first line contains a single integer tt (1≤t≤5001≤t≤500) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105).

It is guaranteed that the sum of nn over all test cases doesn't exceed 3⋅1053⋅105.

Output

For each test case, print a single line containing the string ss. If there are multiple such strings, output any. It can be shown that such string always exists under the given constraints.

Example input
4
3
5
9
19
input output
abc
diane
bbcaabbba
youarethecutestuwuu
output Note

In the first test case, each substring of "abc" occurs exactly once.

In the third test case, each substring of "bbcaabbba" occurs an odd number of times. In particular, "b" occurs 55 times, "a" and "bb" occur 33 times each, and each of the remaining substrings occurs exactly once.

 

——————————————

题意:给定序列s的长度n,构造一个可能的序列满足:s的任何子列在s中出现的次数为奇数次。

思路:

①举例:对于长度为9的序列aaaaaaaaa,子序列a出现了9次,aa出现了8次,aaa出现了7次......aaaaaaaaa出现了9次。而对于长度为8的序列aaaaaaaa,子序列a出现了8次,aa出现了7次,aaa出现了6次......aaaaaaaa出现了8次。

②观察:由上两个例子,可得如下表格

 

 所以,按照子序列的奇偶性去看表格时,当子序列是奇/偶时,为使其次数认为奇数次,可以选择奇+偶来构造

③构造:构造时,需要两串x来满足上面的推论,一串x为奇数个,另一串为偶数个。这样x的总个数是(2*k)+(2*k+1)个。

此时x的任意长度子串必满足出现次数为奇数,前后两串x满足->(前奇后偶,前偶后奇)

若n为偶数,则需要用1个x以外的字符将两串x分隔开(例如y)。

若n为奇数,则需要2个x以外的字符将两串x分隔开。同时,若选择了2个一样的字符,则又会出现不满足奇数个的情况。故只能选用两个不同的,非x的字符(例如y,z)

④一些细节:构造时默认总长度n很大,但是不能遗漏了比如n==1的情况,n==1时只要1个任意字符串就可以。不加特判会按照奇数个的情况起码打印两个非x字符!

最后,上代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        if(n==1)
            cout<<"x"<<endl;
        else
        {
            for(int i=1;i<n/2;i++)
                cout<<"x";
            cout<<"y";
            if(n%2)
                cout<<"z";
            for(int i=0;i<n/2;i++)
                cout<<"x";
            cout<<endl; 
        }        
    }
    return 0;
}
AC代码

 

标签:string,Diane,序列,735,each,test,such,Div,occurs
来源: https://www.cnblogs.com/brucekz/p/15077801.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有