Ural 2037. Richness of binary words 打表找规律 构造
2037. Richness of binary words
题目连接:
http://acm.timus.ru/problem.aspx?space=1&num=2037
Description
For each integer i from 1 to n, you must print a string si of length n consisting of letters ‘a’ and ‘b’ only. The string si 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 : si” where si is one of possible strings. Otherwise, print “i : NO”.
Sample Input
4
Sample Output
1 : NO
2 : NO
3 : NO
4 : aaaa
Hint
题意
让你构造长度为n,字符集为2,且本质不同的回文串恰好i个的字符
无解输出no
题解:
打表找规律,比较容易发现答案其实就是aababb->aaababb->aaaababb的循环,这样的。
然后输出就好了。
代码
#include <bits/stdc++.h>
using namespace std;
int N;
void solve_special(){
if( N <= 7 ){
for(int i = 1 ; i < N ; ++ i) printf("%d : NO\n" , i);
printf("%d : ",N);
for(int j = 1 ; j <= N ; ++ j) putchar('a');
puts("");
}else if( N == 8 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : aababbaa" << endl;
cout << "8 : aaaaaaaa" << endl;
}else if( N == 9 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : NO" << endl;
cout << "8 : aaababbaa" << endl;
cout << "9 : aaaaaaaaa" << endl;
}else if( N == 10 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : NO" << endl;
cout << "8 : aaababbaaa" << endl;
cout << "9 : aaaababbaa" << endl;
cout << "10 : aaaaaaaaaa" << endl;
}
}
void solve(){
int target = (N-11)/2 + 2 ;
for(int i = 1 ; i < 8 ; ++ i){
printf("%d : NO\n" , i);
}
int cur = 2;
for(int i = 8 ; i < N ; ++ i){
int len = 0 , flag = 0 , rs = cur;
printf("%d : " , i);
while( len < N ){
if( flag == 0 ){
putchar('a');
-- rs;
}else if( flag == 1 ){
if( rs == 3 ) putchar('a');
else putchar('b');
-- rs;
}
if( rs == 0 ){
flag ^= 1;
if( flag == 0 ) rs = cur;
else rs = 4;
}
++ len;
}
if( cur == target ) cur += 2;
else ++ cur;
puts("");
}
printf("%d : ",N);
for(int i = 1 ; i <= N ; ++ i) putchar('a');
puts("");
}
int main(int argc,char *argv[]){
//freopen("KO.txt","w",stdout);
scanf("%d",&N);
if( N < 10 ) solve_special();
else if( N == 10 ){
cout << "1 : NO" << endl;
cout << "2 : NO" << endl;
cout << "3 : NO" << endl;
cout << "4 : NO" << endl;
cout << "5 : NO" << endl;
cout << "6 : NO" << endl;
cout << "7 : NO" << endl;
cout << "8 : aaababbaaa" << endl;
cout << "9 : aaaababbaa" << endl;
cout << "10 : aaaaaaaaaa" << endl;
}else solve();
return 0;
}
Ural 2037. Richness of binary words 打表找规律 构造的更多相关文章
- URAL 2037 Richness of binary words (回文子串,找规律)
Richness of binary words 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/B Description Fo ...
- codeforces#1159D. The minimal unique substring(打表找规律+构造)
题目链接: https://codeforces.com/contest/1159/problem/D 题意: 构造一个长度为$n$的$01$串,最小特殊连续字串的长度为$k$ 也就是,存在最小的$k ...
- Ural 2045. Richness of words 打表找规律
2045. Richness of words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2045 Description For ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
随机推荐
- Python配置tab自动补全功能
# cat tab.py #!/usr/bin/python # python tab file import sys import readline import rlcompleter impor ...
- Java入门系列(九)Java API
String,StringBuilder,StringBuffer三者的区别 1.首先说运行速度,或者说是执行速度 在这方面运行速度快慢为:StringBuilder > StringBuffe ...
- 【整理】HTML5游戏开发学习笔记(2)- 弹跳球
1.预备知识(1)在画布上绘制外部图片资源(2)梯度(gradient):HTML5中的对象类型,包括线性梯度和径向梯度.如createLinearGradient,绘制梯度需要颜色组http://w ...
- git的权威指南
CHENYILONG 博客 git的权威指南 全屏 © chenyilong.本站由Postach.io 博客
- springboot 整合 mongodb实现 批量更新数据
现需求:需要批量将1000个数据先查询在更新到mongodb(如果查询不到数据,则添加数据) 1:工具类BathUpdateOptions import org.springframework.dat ...
- mysqldump只导出表结构或只导出数据的实现方法【转】
mysql mysqldump 只导出表结构 不导出数据 mysqldump --opt -d 数据库名 -u root -p > xxx.sql 备份数据库 #mysqldump 数据库名 & ...
- C# 百度搜索结果xpath分析
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- springboot创建一个可执行的jar
让我们通过创建一个完全自包含的可执行jar文件来结束我们的示例,该jar文件可以在生产环境运行.可执行jars(有时候被成为胖jars "fat jars")是包含你的编译后的类和 ...
- java Socket和ServerSocket多线程编程
这是在一本java教材上看到的,做了点修改.具体本教材记不清楚了,Sorry.放在这里,只是让自己需要的时候能够容易找到. 程序分两部分,服务端和客户端.先把服务端运行起来,在运行客户端.整个过程就是 ...
- Ibatis.Net 执行存储过程学习(八)
首先在数据库创建存储过程: create proc [dbo].[usp_GetPersonById] @Id int as begin select Id,Name from Person wher ...