Codeforces805B. 3-palindrome 2017-05-05 08:33 156人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
standard output
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.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int main()
{
int n;
scanf("%d",&n);
int flag=0;
int cnt=0;
for(int i=1; i<=n; i++)
{
if(flag==0) printf("a");
else printf("b");
cnt++;
if(cnt==2)
cnt=0,flag^=1;
}
printf("\n");
return 0;
}
Codeforces805B. 3-palindrome 2017-05-05 08:33 156人阅读 评论(0) 收藏的更多相关文章
- 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏
May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...
- c#委托和事件(下) 分类: C# 2015-03-09 08:42 211人阅读 评论(0) 收藏
C#中的委托和事件(下) 引言 如果你看过了 C#中的委托和事件 一文,我想你对委托和事件已经有了一个基本的认识.但那些远不是委托和事件的全部内容,还有很多的地方没有涉及.本文将讨论委托和事件一些更为 ...
- HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏
Building Shops Time Limit: 2000/1000 MS ...
- .net 实现Office文件预览 Word PPT Excel 2015-01-23 08:47 63人阅读 评论(0) 收藏
先打个广告: .Net交流群:252713569 本人QQ :524808775 欢迎技术探讨, 近期公司要求上传的PPT和Word都需要可以在线预览.. 小弟我是从来没有接触过这一块的东西 感觉很棘 ...
- 基于命令行编译打包phonegap for android应用 分类: Android Phonegap 2015-05-10 10:33 73人阅读 评论(0) 收藏
也许你习惯了使用Eclipse编译和打包Android应用.不过,对于使用html5+js开发的phonegap应用,本文建议你抛弃Eclipse,改为使用命令行模式,绝对的快速和方便. 一直以来,E ...
- walk around by The provided App differs from another App with the same version and product ID 分类: Sharepoint 2015-07-05 08:14 4人阅读 评论(0) 收藏
'm currently developing a SharePoint 2013 application. After a few deployments via Visual Studio, I ...
- hdu 1050 (preinitilization or postcleansing, std::fill) 分类: hdoj 2015-06-18 11:33 34人阅读 评论(0) 收藏
errors, clauses in place, logical ones, should be avoided. #include <cstdio> #include <cstr ...
- hdu 1047 (big integer sum, fgets or scanf, make you func return useful infos) 分类: hdoj 2015-06-18 08:21 39人阅读 评论(0) 收藏
errors made, boundary conditions, <= vs < , decreasing vs increasing , ++, –, '0'/'1' vs 0/1 p ...
- A simple problem 分类: 哈希 HDU 2015-08-06 08:06 1人阅读 评论(0) 收藏
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
随机推荐
- 如何将String转换为int
1. int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String],[int radix]); Integer.parseIn ...
- 安装 neo4j 在 .../bin 目录下使用 ./neo4j 没反应 和 从csv 导入数据到neo4j
可以使用 /bin/sh ./neo4j start 如果提示:./neo4j: 28: set: Illegal option -o pipefail 那么 ubuntu”set Illegal o ...
- 基元线程同步构造之 Mutes(互斥体)
互斥体实现了“互相排斥”(mutual exclusion)同步的简单形式(所以名为互斥体(mutex)). 互斥体禁止多个线程同时进入受保护的代码“临界区”(critical section). 因 ...
- hdoj1003 DP
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- #define宏常量和const常量的区别
C++ 语言可以用const 来定义常量,也可以用#define 来定义常量.但是前者比后者有更多的优点:(1) const 常量有数据类型,而宏常量没有数据类型.编译器可以对前者进行类型安全检查.而 ...
- Python中类的定义与使用
目标: 1.类的定义 2.父类,子类定义,以及子类调用父类 3.类的组合使用 4.内置功能 1.类的定义 代码如下: #!/usr/bin/env python #coding:utf8 class ...
- node.js压缩版 Windows安装
1.下载 下载地址:https://nodejs.org/zh-cn/download/ 选择相应的版本下载 2.解压缩 将文件解压到要安装的位置,并新建两个目录 node-global :npm全局 ...
- c++ tricks
1 关于virtual关键字的实验 1.1 在派生类中改变virtual函数访问权限 定义两个类A,B,其中B公有派生于A.A中定义一个private成员虚函数func,B中覆写此函数,但是将其访问权 ...
- 白盒静态自动化测试工具:FindBugs使用指南
目 录 1 FINDBUGS介绍 2 在ECLIPSE中安装FINDBUGS插件 3 在ECLIPSE中使用FINDBUGS操作步骤 3.1 ...
- Python3 urllib库和requests库
1. Python3 使用urllib库请求网络 1.1 基于urllib库的GET请求 请求百度首页www.baidu.com ,不添加请求头信息: import urllib.requests d ...