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 ...
随机推荐
- Linux线程属性总结
线程属性标识符:pthread_attr_t 包含在 pthread.h 头文件中. //线程属性结构如下: typedef struct { int etachs ...
- soap协议有get方式
今天去面试,被问到了这个问题.一时没想起来.考官的说法是没有 get,使用post 发请求.restful 有get put delete等谓词. 特地查了一下.记在下边. <system.we ...
- 自定义View(1)简单流程及示例模板
1,继承View , ViewGroup,或TextView等等 2,绘制相关的api, canvas 画布, paint 画笔 2,重写重要的函数(注意这个顺序) onMeasure 属于View的 ...
- 对github中项目进行更新
进入本地仓库文件夹,我的仓库名是tufujiegit,然后 进入 git clone 接着将先前记录下来的地址复制到后面,回车 将下载github中该仓库的所有文件及文件夹,包括.git文件夹在内 ...
- IntelliJ IDEA For Mac 快捷键——常用版
一.搜索 搜索文件 command+shift+n 打开方法实现类 command+option+b 全文搜索 ctrl+shift+f (1)类和方法 查看类的继承结构 ctrl+h 查看方法的 ...
- 设置COOKIE过期时间的方法
第一,日期运算法 1)将期限设置为当前日期后的第N天的0时0分0秒 Response.Cookies(LastView).Expires=dateadd(d,N,date) 2)将期限设置为当前日期后 ...
- perl基本语法
标量 标量是 Perl 中最简单的数据类型.大多数的标量是数字(如 255 或 3.25e20)或者字符串(如 hello或者盖茨堡地址). 数字 perl中所有数字内部的格式都是双精度浮点数. 浮点 ...
- MySQL学习笔记一
MySQL 学习笔记 一 一.数据库简单介绍 1. 按照数据库的发展时间顺序,主要出现了以下类型数据库系统: Ø 网状型数据库 Ø 层次型数据库 Ø 关系型数据库 Ø 面向对象数据库 上面4中数据库系 ...
- 设置图片Alpha
Drawable ico = getResources().getDrawable(R.drawable.search_box); mSearchLayou ...
- UVa 11076 (有重元素的排列) Add Again
n个可重复的元素的排列一共有 = All种,其中 假设这些数依次为ai,每种数字有mi个. 从右往左考虑第d位数(d≥0),第i个数字出现的次数为,那么这个数字对所求答案的贡献为 其实可以先一次求出个 ...