CF411div2 B. 3-palindrome

xiaoxiao2021-02-27  192

In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.

He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

Input The first line contains single integer  n  ( 1 ≤ n ≤ 2·105 ) — the length of the string. Output

Print the string that satisfies all the constraints.

If there are multiple answers, print any of them.

Examples input 2 output aa input 3 output

bba

只要没有三个是回文的 直接输出aabbaabbaabb这个形式的 这个任意三个数没有回文 而且没有c

#include <stdio.h> #include <string.h> #include <bits/stdc++.h> #define mod 1000000007 #define ll long long using namespace std; int main() { int n; cin>>n; int k=1; for(int i=0;i<n;i++){ if(i%2==0)k*=-1; if(k==1)printf("%c",'b'); else printf("%c",'a'); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-12089.html

最新回复(0)