B. 3-palindrome
time limit per test

1 second

memory limit per test

256 megabytes

 

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.

 
input
2
output
aa
input
3
output
bba
Note:

A palindrome is a sequence of characters which reads the same backward and forward.

---------------------------------------华丽的分割线--------------------------------------------

题目大意: 输入一个整数n,代表字符串的长度

     输出一个字符串(该字符串自包含a、b、c三种字符,且不会出现长度为3的回文字符串,保证c字符的个数出现的尽量少)

解题思路:

     该题最重要的要保证字符串中不会出现长度为3的回文字符串,我们可以先设计一个“子串”,保证以这个子串为基础的字符串不会出现长度为3的回文字符串即可

     例如 “aabb” 当然也可以是别的哈(但是长度要尽量的短)

     题目要求c字符的个数要尽可能的少,我们不输出c字符就好了。

AC代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std; int main ()
{
int n,i;
while (~scanf("%d",&n))
{
if (n == )
printf("a\n");
else if (n == )
printf("ab\n");
else if(n == )
printf("aab\n");
else{
for (i = ; i < n/; i ++) // 处理最后剩余长度不足4的情况
printf("aabb");
for (i = ; i < n%; i ++){
if (i >= )
printf("b");
else
printf("a");
}
printf("\n");
}
}
return ;
}

Codeforces Round #411 B. 3-palindrome的更多相关文章

  1. Educational Codeforces Round 2 C. Make Palindrome 贪心

    C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  2. Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)

    A. Fake NP time limit per test:1 second memory limit per test:256 megabytes input:standard input out ...

  3. Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串

    题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...

  4. Codeforces Round #411 (Div. 2) A-F

    比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...

  5. Codeforces Round 411 Div.2 题解

    A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...

  6. Codeforces Round #411 (Div. 1) D. Expected diameter of a tree

    题目大意:给出一个森林,每次询问给出u,v,问从u所在连通块中随机选出一个点与v所在连通块中随机选出一个点相连,连出的树的直径期望(不是树输出-1).(n,q<=10^5) 解法:预处理出各连通 ...

  7. Codeforces Round #411 (Div. 2)

    来自FallDream的博客,未经允许,请勿转载,谢谢. 由于人傻又菜 所以这次又滚去div2了  一堆结论题真的可怕 看见E题不是很有思路   然后就去大力搞F题  T了最后一个点 真的绝望   但 ...

  8. Codeforces Round #411 div 2 D. Minimum number of steps

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. Codeforces Round #411 (Div. 2) 【ABCDE】

    A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...

随机推荐

  1. 03. PNG,GIF,JPG的区别及如何选?

      3.PNG,GIF,JPG的区别及如何选? 照片用 JPG. 动画用 GIF. Logo.Icon 等小图用 PNG-8. 非特殊情况,尽量不要用 PNG-24 和 PNG-32.  

  2. css modules

    https://juejin.im/post/5aa727fc518825364001159b http://www.ruanyifeng.com/blog/2016/06/css_modules.h ...

  3. spotless-maven-plugin java代码自动格式化mvn spotless:apply -fn

    <plugin> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven ...

  4. find命令用法集锦

    find命令用法: 01--过滤日志find -name "catelina.*.out"|xargs -f |grep '关键字' 02 -忽略一个目录或者多个目录find ./ ...

  5. 微信小程序回到顶部的两种方式

    一,使用view形式的回到顶部 <image src='../../img/button-top.png' class='goTop' hidden='{{!floorstatus}}' bin ...

  6. vue,新手上路,基础,常见问题

    1. 报这个错的  都是关键字问题,不要用关键字 做为组件的名字,不然肯定都会报错,如果找不到就一个字母的看,我就是 忘记改组件的名字导致报错,这个问题   改个名字就好,切记改全不然只有页面报错,文 ...

  7. python any和all

    摘自<流畅的Python> all 和 any 也是内置的归约函数. all(iterable) 如果 iterable 的每个元素都是真值,返回 True:all([]) 返回 True ...

  8. Spark on YARN简介与运行wordcount(master、slave1和slave2)(博主推荐)

    前期博客 Spark on YARN模式的安装(spark-1.6.1-bin-hadoop2.6.tgz +hadoop-2.6.0.tar.gz)(master.slave1和slave2)(博主 ...

  9. gcd函数两种实现(参考)

    注意: %a= a%-----溢出 递归: #include<stdio.h> int gcd(m,n) { int g; ) g=m; else g=gcd(n,m%n) return ...

  10. Hibernate 一对一映射(共享主键)