Codeforces Round #411 B. 3-palindrome
1 second
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.
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
2
aa
3
bba
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的更多相关文章
- Educational Codeforces Round 2 C. Make Palindrome 贪心
C. Make Palindrome Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- 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 ...
- Educational Codeforces Round 2 C. Make Palindrome —— 贪心 + 回文串
题目链接:http://codeforces.com/contest/600/problem/C C. Make Palindrome time limit per test 2 seconds me ...
- Codeforces Round #411 (Div. 2) A-F
比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...
- Codeforces Round 411 Div.2 题解
A Fake NP standard input/output s, MB Submit Add to favourites x3673 B -palindrome standard input/ou ...
- Codeforces Round #411 (Div. 1) D. Expected diameter of a tree
题目大意:给出一个森林,每次询问给出u,v,问从u所在连通块中随机选出一个点与v所在连通块中随机选出一个点相连,连出的树的直径期望(不是树输出-1).(n,q<=10^5) 解法:预处理出各连通 ...
- Codeforces Round #411 (Div. 2)
来自FallDream的博客,未经允许,请勿转载,谢谢. 由于人傻又菜 所以这次又滚去div2了 一堆结论题真的可怕 看见E题不是很有思路 然后就去大力搞F题 T了最后一个点 真的绝望 但 ...
- 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 ...
- Codeforces Round #411 (Div. 2) 【ABCDE】
A. Fake NP 题意:给你l,r,让你输出[l,r]里面除1以外的,出现因子数量最多的那个数. 题解:如果l==r输出l,否则都输出2 #include<bits/stdc++.h> ...
随机推荐
- hdu1495 bfs搜索、模拟
大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多.但see ...
- 经典C面试真题精讲
第一章 灵魂--指针 101. p++ 请分析下述代码的输出结果 int main() { char* p1 = "China"; char* p2, * p3; p2 = (); ...
- springboot利用fastjson序列化输出(默认是jackson)
在@SpringBootApplication类中添加 @Bean public HttpMessageConverters fastJsonHttpMessageConverters() { //创 ...
- Bellman-Ford(BF)和Floyd算法
以下只是本人的笔记,想法我自己都怀疑,内容不作为参考, Floyd算法就比较暴力了,算法思想是三重循环,直接枚举所有的顶点,再两次for循环枚举所有点,验证以第一个点为中转点的两个点是否路径更短,具体 ...
- HTML5离线资源缓存简介
cache manifest 示例 要使用离线资源缓存,开发者首先要提供一个 cache manifest 文件 它列出了所有需要在离线状态下使用的资源,浏览器会把这些资源缓存到本地 下面就是一个 c ...
- linux diff(differential) 命令
功能说明:比较文件的差异. 语法:diff [OPTION]... FILES 实例: diff -ur temp1 temp2 diff -ur temp1 temp2 > temp.diff ...
- FZU 2138——久违的月赛之一——————【贪心】
久违的月赛之一 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- plpgsql insert 性能 测试
有时需要执行一些sql脚本,带逻辑控制语句,又不想用高级语言C#.Java之类的,可以直接用plpgsql,类似于Oracle的plsql. do language 'plpgsql' $$ decl ...
- C#项目””是针对”.NETFramework,Version=v4.5.2”但此计算机没有,需要修改为v4.5.1.
每次下载别人的代码都会出现这样的问题,以为是没有安装.NETFramework,就下载安装了,但是每次安装都会出现已安装高版本的4.6(Win10自带),无需下次安装,但是每次VS中都会显示有问题,而 ...
- 一:Shiro知识整理
一:springboot快速入门: 1.建立Maven项目,导入springboot父工程 <!-- 继承springboot默认父工程 --> <parent> <gr ...