3-palindrome CodeForces - 805B (思维)
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.
Examples
2
aa
3
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
题意:给你一个整数N,让你输出一个字符串,只包括abc三个字符串,并且它的所有长度为3的子串不能使回文串,并且c字符要求尽可能的少。
思路:既然要求c字符出现的尽可能的少,那么设想下是否可以不用c字符来构造出这个字符串。
通过思考可以发现,仅用两个字符ab,可以通过连续两个相同的字符来构造出整个字符串
即aabb,aabbaa,aabba,aab,aabbaabb,这样的。并且一定符合条件。
我们只需要用代码实现出来就好了。
我的AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/ int main()
{
ll l,r;
cin>>l>>r;
if(l==r)
{
cout<<l<<endl;
}else
{
if(r-l>=)
{
cout<<<<endl;
}else
{
cout<<l<<endl;
}
}
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
3-palindrome CodeForces - 805B (思维)的更多相关文章
- Make Palindrome CodeForces - 600C(思维)
A string is called palindrome if it reads the same from left to right and from right to left. For ex ...
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- POJ2402/UVA 12050 Palindrome Numbers 数学思维
A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example,the ...
- Codeforces 1060E(思维+贡献法)
https://codeforces.com/contest/1060/problem/E 题意 给一颗树,在原始的图中假如两个点连向同一个点,这两个点之间就可以连一条边,定义两点之间的长度为两点之间 ...
- Queue CodeForces - 353D (思维dp)
https://codeforces.com/problemset/problem/353/D 大意:给定字符串, 每一秒, 若F在M的右侧, 则交换M与F, 求多少秒后F全在M左侧 $dp[i]$为 ...
- 【codeforces 805B】3-palindrome
[题目链接]:http://codeforces.com/contest/805/problem/B [题意] 让你生成一个只包含a,b,c的字符串; 要求c出现的次数最少,且任意一个 长度为3的子串 ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
- CodeForces - 417B (思维题)
Crash Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
随机推荐
- UG/NX 8.0安装方法(图文详解)
UG8.0,自从被西门子收购后改名为NX,也称NX8.0,作为一款非常优秀三维模具设计软件.他可以针对用户的虚拟产品设计和工艺设计的需求,提供经过实践验证的解决方案.其以全面的设计概念.良好的界面受到 ...
- Python3中PyMongo的用法
MongoDB存储 在这里我们来看一下Python3下MongoDB的存储操作,在本节开始之前请确保你已经安装好了MongoDB并启动了其服务,另外安装好了Python的PyMongo库. 连接Mon ...
- 【转】抓包工具Fiddler的使用教程(十二)下:Fiddler抓取HTTPS
在教程十二(上),我们也了解了HTTPS协议,该教程就和大家分享Fiddler如何抓取HTTPS 抓包工具Fiddler的使用教程(十二):[转载]HTTPS协议 再次回忆一下关键内容: iddler ...
- Cookie、sessionStorage与localStorage的区别
(1) sessionStorage 保存数据的方法: SessionStor.setItem(“key”,”value”) 或者写成 sessionStorage.key=”value” 读取数据的 ...
- Intel支持八九代酷睿的B365芯片组将登场亮相
不久前,Intel悄然推出了新款芯片组B365,看起来像是B360的升级版,但事实上二者并无太大关系. 根据最新曝料,基于B365芯片组的主板将在1月16日登场亮相,支持八九代酷睿. 同时获悉,B36 ...
- Java并发(五)线程池使用番外-分析RejectedExecutionException异常
目录 一.入门示例 二.异常场景1 三.异常场景2 四.解决方法 之前在使用线程池的时候,出现了 java.util.concurrent.RejectedExecutionException ,原因 ...
- python inspect.stack() 的简单使用
1. #python # -*- encoding: utf-8 -*- #获取函数的名字 import inspect def debug(): callnamer = inspect.stack( ...
- 看进程的启动时间长度 + vmstat + jstack 应用
1.显示进程已运行的时间 $ ps -e -o pid,comm,etime 2.dd不断的向磁盘写入数据,所以bo的值会骤然提高,而cpu的wait数值也变高,说明由于大量的IO操作,系统的瓶径出现 ...
- Spark笔记-DataSet,DataFrame
DataSet:面向对象的,从JVM进行构建,或从其它格式进行转化 DataFrame:面向SQL查询,从多种数据源进行构建,或从其它格式进行转化 RDD DataSet DataFrame互转 1. ...
- 1-Android开发验证码(使用第三方Mob,注册)
http://www.mob.com/ 注册以后 可以直接放在 可以下载到手机里面试一下了 后续就不截图了 补充: 自定义签名