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> ...
随机推荐
- 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest
题目传送门 只打了三个小时. A. Broadcast Stations B. Connect3 补题:zz 题解:因为格子是4*4的,而且每次落子的位置最多是只有四个,再加上剪枝,情况不会很多,直接 ...
- [短期持续更新]Codeforces 构造题一览
说实话我觉得做这种题很没意思(不够硬核), 可是人有短板终究是要补的...起码这种类型补起来相对简单 所以还是把先前准备好的专题放下吧,做点实现上比较休闲的题 ps.为了精简篇幅,代码全部丢到ubun ...
- Bowen
Advertise Window大小 注册表键值位于:regedit->HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Pa ...
- AXI协议(一)
最近弄Zynq,不懂AXI协议Zynq很难玩儿的转.这些笔记主要攻克AXI中的一些难题. 所有的AXI4包含了5个不同的通道: (1)读/写地址通道(Read/Write address ch ...
- python爬虫之urllib库(一)
python爬虫之urllib库(一) urllib库 urllib库是python提供的一种用于操作URL的模块,python2中是urllib和urllib2两个库文件,python3中整合在了u ...
- SVM面经
原始问题与对偶问题的关系 1,目标函数对原始问题是极大化,对对偶问题则是极小化 2,原始问题目标函数中的收益系数(优化函数中变量前面的系数)是对偶问题约束不等式中的右端常数,而原始问题约束不等式中的右 ...
- Java_方法的调用②及案例
语法格式: 方法名称([参数列表]); //注意:只能调用本类的方法 案例: class Method01{ public static void print(){ for(int i = 1; i ...
- (转)shell变量及扩展
1.shell变量 shell变量赋值语句为”name=[value]“,等号两边不能有空格,可以给shell变量追加内容”name+=value“,取消shell变量的设置使用”unset name ...
- (转)【MySQL】sync_binlog innodb_flush_log_at_trx_commit 浅析
原文:http://blog.itpub.net/22664653/viewspace-1063134/ innodb_flush_log_at_trx_commit和sync_binlog 两个参 ...
- Python实现WEB QQ 登录与消息发送(第一版本 2015.06.26)
WEB QQ的登录步骤与协议,需要的度娘下,很多. 转载说明来源:http://www.cnblogs.com/ryhan/p/4602762.html 我这实现是参考了度娘搜的 和自己抓包分析的. ...