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. The model backing the 'XXX' context has changed 错误

    https://blog.csdn.net/hit_why/article/details/72778785 https://blog.csdn.net/hit_why/article/details ...

  2. 关于导入本地maven项目pom.xml出现missing artifact org....报错处理

    一.导入本地maven项目步骤:

  3. 编写高质量代码:Web前端开发修炼之道(二)

    第四章:高质量的css 1)怪异模式和标准模式 在标准模式中,浏览器根据规范表现页面:而怪异模式通常模拟老式浏览器的行为以防止老站点无法工作. 他们两者之间的差异比较典型的表现在IE对盒模型的解析:在 ...

  4. DedeCMS实现自定义表单提交后发送指定QQ邮箱的方法

    如月cruyue在做DedeCMS自定义表单发送邮箱的教程,发现大部分都是在php文件里写死固定字段内容,这样虽然也能实现自定义表单提交后发送指定邮箱,但是很不智能,如月cruyue想要一个我们自定义 ...

  5. linux 查看进程启动时,用户的工作目录

    在linux下查看进程大家都会想到用 ps -ef|grep XXX可是看到的不是全路径,怎么看全路径呢?每个进程启动之后在 /proc下面有一个于pid对应的路径例如:ps -ef|grep pyt ...

  6. Shell检查程序是否正常,并显示出程序启动时间、执行时间

    项目中多个实例,而每个实例均启动一个程序,本脚本将多个程序统一进行监控,并支持文件配置 #!/bin/sh bin=$(cd ``;pwd) cd ${bin} ### 定义检查函数 chkProgr ...

  7. SpringBoot内嵌Tomcat开启APR模式(运行环境为Centos7)

    网上查到的一些springboot内嵌的tomcat开启apr的文章,好像使用的springboot版本较老,在SpringBoot 2.0.4.RELEASE中已经行不通了.自己整理了一下,供参考. ...

  8. oracle--dump->buffer cache (dump 深入实践一)

    1,dump 取值 ALTER SESSION SET EVENTS 'immediate trace name buffers level n'; 只转储buffer header. 在level ...

  9. unity 渲染第二步

    先不要用 unity shader 提供给你的转换矩阵,看看屏幕上的图形,你会学到更多. --- <unity 渲染箴言> 假设你 create 了一个 cube,放在默认的位置,默认的 ...

  10. db2 monitor event

    1.创建事件监控器至少需要哪些权限? DBADM authority SQLADM authority 2.事件监控器的种类有哪些? 3. db2 flush event monitor eventm ...