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 ...
随机推荐
- 网络_OSI模型_数据包传输
2017年1月12日, 星期四 网络_OSI模型_数据包传输 1. 网络_源主机_局域网_交换机_路由器_目标主机 2. OSI7七层_TCP/IP精简 OSI 7层: 应用层 ...
- python assert 断言语句的作用
python assert 断言语句的作用 assert语句的应用场景 使用assert语句是一个很好的习惯. 我们在编写代码的时候, 不知道程序会在什么时候崩溃, 与其让它在深度运行时崩溃, 不如预 ...
- 20155232 2016-2017-3 《Java程序设计》第8周学习总结
20155232 2016-2017-3 <Java程序设计>第8周学习总结 教材学习内容总结 第十四章NIO与NIO2 NIO使用频道来衔接数据结点,在处理数据时,NIO可以让你设定缓冲 ...
- expect 交互 模拟ssh 登陆
模拟ssh登录 #!/bin/bash Ip='192.168.1.6' # 循环就行 RemoteUser='user' # 普通用户 RemotePasswd='userpasswd' # 普通用 ...
- HDU 3787 A+B 模拟题
解题报告:就是输入两个用逗号隔开的数字,求出这两个数字的和,并且用正常的方式输出来.直接写一个函数将一个包含逗号的数字转换成十进制的数返回就行了.这里推荐一个函数atoi(),参数是char*型的,然 ...
- c++刷题(39/100)笔试题3
题目1: 现在你需要用一台奇怪的打字机书写一封书信.信的每行只能容纳宽度为100的字符,也就是说如果写下某个字符会导致行宽超过100,那么就要另起一行书写 信的内容由a-z的26个小写字母构成,而每个 ...
- mysql.user细节三问
一.如何拒绝用户从某个精确ip访问数据库假如在mysql.user表中存在用户'mydba'@'192.168.85.%',现在想拒绝此用户从某个精确ip访问数据库 # 创建精确ip用户,分配不同的密 ...
- 运算符,比如+, -, >, <, 以及下标引用[start:end]等等,从根本上都是定义在类内部的方法。
python解释器在碰到+号运算符时,会调用加号前面的对象的__add__方法 class a: def __add__(self,b): print "ghh" aa=a() a ...
- WCF使用Net.tcp绑定时候出现错误:元数据包含无法解析的引用
在WCF服务编程中,客户端添加引用服务时,出现如下错误: 元数据包含无法解析的引用:“net.tcp://192.168.1.105:1314/LoginService”. 套接字连接已中止.这可能是 ...
- IIS7配置HTTPS+默认访问https路径
一.下载证书(这里我使用的是阿里云免费的证书) 文件说明: 1. 1532858285913.key(证书私钥文件).1532858285913.pem(证书文件).1532858285913.pfx ...