URAL 2037 Richness of binary words (回文子串,找规律)
Richness of binary words
题目链接:
http://acm.hust.edu.cn/vjudge/contest/126823#problem/B
Description
For each integer i from 1 to n, you must print a string s i of length n consisting of letters ‘a’ and ‘b’ only. The string s i must contain exactly i distinct palindrome substrings. Two substrings are considered distinct if they are different as strings.
Input
The input contains one integer n (1 ≤ n ≤ 2000).
Output
You must print n lines. If for some i, the answer exists, print it in the form “ i : s i” where s i is one of possible strings. Otherwise, print “ i : NO”.
Sample Input
input output
4
1 : NO
2 : NO
3 : NO
4 : aaaa
##题意:
要求输出n个长度为n的字符串(只能放a或b):
要求Si中不同回文子串的个数恰为i.
##题解:
本质就是找出一种构造方式使得回文子串个数不会再增加.
参考2015-ICPC合肥现场赛H题:
http://blog.csdn.net/snowy_smile/article/details/49870109
http://blog.csdn.net/keshuai19940722/article/details/49839359
##代码:
``` cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define eps 1e-8
#define maxn 210000
#define mod 100000007
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n;
int main(int argc, char const *argv[])
{
//IN;
while(scanf("%d", &n) != EOF)
{
if(n == 1) {
printf("1 : a\n");
continue;
}
if(n == 2) {
printf("1 : NO\n");
printf("2 : ab\n");
continue;
}
if(n < 8) {
for(int i=1; i<n; i++)
printf("%d : NO\n", i);
printf("%d : ", n);
for(int i=1; i<=n; i++)
putchar('a');
printf("\n");
continue;
}
if(n == 8) {
for(int i=1; i<7; i++)
printf("%d : NO\n", i);
printf("7 : aababbaa\n");
printf("8 : ");
for(int i=1; i<=n; i++)
putchar('a');
printf("\n");
continue;
}
char str[] = "abaabb";
for(int i=1; i<=7; i++)
printf("%d : NO\n", i);
for(int i=8; i<=n; i++) {
printf("%d : ", i);
for(int j=1,cur=0; j<=n; j++) {
if(j <= i-8) putchar('a');
else {
if(cur == 6) cur = 0;
putchar(str[cur++]);
}
}
printf("\n");
}
}
return 0;
}
URAL 2037 Richness of binary words (回文子串,找规律)的更多相关文章
- URAL 2045 Richness of words (回文子串,贪心)
Richness of words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/J Description For each ...
- Ural 2037. Richness of binary words 打表找规律 构造
2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...
- Ural 1297 Palindrome 【最长回文子串】
最长回文子串 相关资料: 1.暴力法 2.动态规划 3.中心扩展 4.Manacher法 http://blog.csdn.net/ywhorizen/article/details/6629268 ...
- ural 1297 后缀数组 最长回文子串
https://vjudge.net/problem/URAL-1297 题意: 给出一个字符串求最长回文子串 代码: //论文题,把字符串反过来复制一遍到后边,中间用一个没出现的字符隔开,然后就是枚 ...
- POJ2402 Palindrome Numbers第K个回文数——找规律
问题 给一个数k,给出第k个回文数 链接 题解 打表找规律,详见https://www.cnblogs.com/lfri/p/10459982.html,差别仅在于这里从1数起. AC代码 #inc ...
- 【URAL 1297】Palindrome 最长回文子串
模板题,,,模板打错查了1h+QAQ #include<cmath> #include<cstdio> #include<cstring> #include< ...
- Leetcode_5.最长回文子串
最长回文子串 题目描述: 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab& ...
- URAL 1297 最长回文子串(后缀数组)
1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a ...
- 后缀数组 - 求最长回文子串 + 模板题 --- ural 1297
1297. Palindrome Time Limit: 1.0 secondMemory Limit: 16 MB The “U.S. Robots” HQ has just received a ...
随机推荐
- 22.allegro中PCB打印设置[原创]
1. -- 2. 3. 4. ----
- php整理(一):变量和字符串
PHP中的变量: 1. 定义:$符号来定义变量 2. 说明: (1)PHP弱语言,定义变量的时候不用声明类型,但是并不代表PHP没有数据类型 (2)变量名是区分大小写的,只能是数字,字母或者下划线 ( ...
- [HDOJ4022]Bombing(离散化+stl)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4022 一个图上有n个点,之后m个操作,每次操作一行或者一列.使得这一行或者这一列的点全部消除.每次操作 ...
- @interface java注解
@Documented,@Retention,@Target,@Inherited 1. 编写自定义@Todo注解经常我们在写程序时,有时候有些功能在当前的版本中并不提供,或由于某些其它原因,有些方法 ...
- bzoj1913
这是一道好题,要求每个三点圆覆盖的点数和 我们可以算四边形的贡献,四边形显然分成两种:凸四边形和凹四边形 显然,凹四边形的覆盖只可能是三个点组成三角形包含另一个点,所以贡献是1 凸四边形,其最小圆覆盖 ...
- RTP协议学习大总结从原理到代码
from:http://wenku.baidu.com/view/aaad3d136edb6f1aff001fa5.html 一.流媒体概念 流媒体包含广义和狭义两种内涵:广义上的流媒体指的是使音频和 ...
- Android UncaughtExceptionHandler,捕获错误
最近在做个项目,需要在程序出现运行时异常和错误导致程序crash时进行一些操作,找到一个方法 Thread.setDefaultUncaughtExceptionHandler(new Uncaugh ...
- hdu 3342 Legal or Not(拓扑排序) HDOJ Monthly Contest – 2010.03.06
一道极其水的拓扑排序……但是我还是要把它发出来,原因很简单,连错12次…… 题意也很裸,前面的废话不用看,直接看输入 输入n, m表示从0到n-1共n个人,有m组关系 截下来m组,每组输入a, b表示 ...
- Generate Parentheses java实现
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- MultiSet
Guava引进了JDK里没有的,但是非常有用的一些新的集合类型.所有这些新集合类型都能和JDK里的集合平滑集成.Guava集合非常精准地实现了JDK定义的接口.Guava中定义的新集合有: Multi ...