【codeforces 805B】3-palindrome
【题目链接】:http://codeforces.com/contest/805/problem/B
【题意】
让你生成一个只包含a,b,c的字符串;
要求c出现的次数最少,且任意一个 长度为3的子串都不为回文。
【题解】
随便生成一个
abb
然后对于第i位
只要不和第i-2位一样就可以了;
这样就可以只用a和b构成这个字符串了,不包括c,肯定是最优的了.
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
int n;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n;
if (n==1)
cout <<"a"<<endl;
else
if (n==2)
cout <<"bb"<<endl;
else
if (n>=3)
{
string s = "abb";
rep1(i,3,n-1)
{
if (s[i-2]=='b')
s+='a';
else
s+='b';
}
cout << s <<endl;
}
return 0;
}
【codeforces 805B】3-palindrome的更多相关文章
- 【Codeforces 600C】Make Palindrome
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 计算出来每个字母出现的次数. 把字典序大的奇数出现次数的字母换成字典序小的奇数出现次数的字母贪心即可. 注意只有一个字母的情况 然后贪心地把字 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 798A】Mike and palindrome
[题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【25.64%】【codeforces 570E】Pig and Palindromes
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【44.19%】【codeforces 608D】Zuma
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- [剑指offer]Q13:O(1)时间删除链表的结点
通常我们所说的删除链表的某个结点,是彻底删除该结点的空间.而要这么做就必须知道其前驱结点.这里的想法是,链表中存储的val是同类型的,仅仅要将该结点的val内容删除就能够了. 那么就能够用该结点的后继 ...
- Android学习笔记(8):ViewGroup类
A ViewGroup is a special view that can contain other views (called children.) The view group is the ...
- linux下Oracle11g RAC搭建(七)
linux下Oracle11g RAC搭建(七) 六.安装Grid 启动GRID安装界面 方式一:redhat下调整分辨率 [root@node1 ~]# xhost + //授权 [ro ...
- 【cl】java变量
知识点一: 变量:有声明,有初始化! 变量作用域:变量在声明的地方开始,到块结束(其中一对{}叫块) 变量不能重复声明(声明=定义):在同一个作用域中不能重复声明变量! 在作用域中如果已经有变量了,就 ...
- springmvc之@Controller、@RequestMapping等注解解说
首先来看下一段代码: @Controller @RequestMapping("/user") public class UsersController { @RequestMap ...
- mysql 10060远程不能访问
1.网络不通. 检查能不能ping通. 2.防火墙设置. 防火墙是否放过MySQL的进程,是否屏蔽了mysql的3306端口. 3.mysql的账户设置. mysql账户是否不允许远程连接.如果无法连 ...
- [JavaEE] Apache Maven 入门篇(下)
http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html 作 ...
- Arduino-OLED-四度显示
double Fahrenheit(double celsius) { ; } //摄氏温度度转化为华氏温度 double Kelvin(double celsius) { return celsiu ...
- Ubuntu16.04系统下汉字显示为方框解决办法(图文详解)
不多说,直接上干货! 问题详情 问题分析 今天一打开Ubuntu系统,竟然不支持中文显示了.开始时以为是搜狗拼音的问题,然后重装了一遍fcitx,然后用重装了一遍搜狗输入法.可是重装后问题根本没有解决 ...
- (转)(C++)关于抽象基类和纯虚函数
★抽象类:一个类可以抽象出不同的对象来表达一个抽象的概念和通用的接口,这个类不能实例化(创造)对象. ★纯虚函数(pure virtual):在本类里不能有实现(描述功能),实现需要在子类中实现.例: ...