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. JAVA中 package 和 import 的使用

    1.打包--package 包名一般为小写,而类名的第一个字母一般为大写,这样在引用时,可以明显的分辨出包名和类名.如果在类的定义之前没有使用package定义包名,那么该类就属于缺 省的包. 1.1 ...

  2. [转] Ansible 系列之 Playbooks 剧本

    [From] https://www.cnblogs.com/hanyifeng/p/6435875.html 一.Playbooks 介绍 1.Playbooks是Ansible的配置,部署和编排语 ...

  3. linux vi文本编辑器三种模式切换及常用操作

    初学者刚进入vi不要乱点键盘,vi的三种模式和各种命令很容易弄混@@ vi编辑器是Unix系统最初的编辑器.它使用控制台图形模式来模拟文本编辑窗口,允许查看文件中的行.在文件中移动.插入.编辑和替换文 ...

  4. docker编排工具,docker-compose下载与安装

    安装很简单,但是难免会遇到问题:1.安装curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compos ...

  5. linux(ubuntu-16.1) 下安装 odoo10 新版

    1.虚拟机(VMware)中安装 ubuntu-16.1(网络适配器选择桥接模式). 安装成功后,运行 ubuntu 提示 "CPU已被客户机操作系统禁用" 时,需要修改配置文件解 ...

  6. 关于display:none;和id特性的一些需要注意的地方

    关注点一: display:none;一旦用于某个元素,那个这个元素在页面中就不再占据位置. visibility:hidden;用于某个元素时,这个元素还会占据位置. 关注点二: 即使使用了disp ...

  7. MySQL多表更新

    多表更新:参照另外的表来更新本表的内容 table_reference {[inner | cross] join | {left | right} [outer] join}  内连接.左外连接.右 ...

  8. selenium+Python(cookie处理)

    cookie 处理本节重点: driver.get_cookies() 获得 cookie 信息 add_cookie(cookie_dict) 向 cookie 添加会话信息 delete_cook ...

  9. 8.28_the end

    HomeWork the first level 1. 盒模型 #parent { width: 100px; height: 100px; background:black; overflow: h ...

  10. 九度oj题目1341:艾薇儿的演唱会

    题目1341:艾薇儿的演唱会(40分) 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:522 解决:237 题目描述: 艾薇儿今天来到了中国,她计划两天后在哈尔滨举行一场个人的演唱会.由于 ...