Codeforces 805B 3-palindrome

xiaoxiao2021-02-28  155

题意:

         用 a b c 三个字符构造一个长度为 N 的串,保证串中不出现长度大于等于 3 的回文串 并且 尽可能使字符 c 出现的次数最少。

思路:

        串用 aabb 构造即可满足题意

        例:长度为 3 的串为 aab

                             5              aabba

                             8              aabbaabb

代码:

#include <bits/stdc++.h> using namespace std; int main() { int n; while(scanf("%d",&n)!=-1){ int cut=0; for(int i=0;i<n;i++){ cut%=4; if(cut<2) printf("a"); else printf("b"); cut++; } puts(""); } }

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

最新回复(0)