括弧,这是一个错误的做法,并不能AC

题目描述

Byteasar wants to put a rather long pattern on his house. In order to do this, he has to prepare an appropriate template with letters cut off first. He is going to put the pattern on the wall by putting the pattern on the wall in the appropriate place and painting over it. This way he can "print" all the letters that are on the template at one time (it is not possible to "print" only some of them). It is, however, possible, to paint some letters on the wall several times, as a result of different applications of the template. The letters on the template are adjacent (there are no spaces on it). Of course, it is possible to prepare a template with the whole pattern on it. But Byteasar would like to minimize the cost, so he wants to make a template as short as possible.

TaskWrite a programme that:

reads from the standard input the pattern Byteasar wants to put on his house,determines the minimal length of the template needed to do it,writes the result to the standard output.

Byteasar 想在墙上涂一段很长的字符,他为了做这件事从字符的前面一段中截取了一段作为模版. 然后将模版重复喷涂到相应的位置后就得到了他想要的字符序列.一个字符可以被喷涂很多次,但是一个位置不能喷涂不同的字符.做一个模版很费工夫,所以他想要模版的长度尽量小,求最小长度是多少.拿样例来说 ababbababbabababbabababbababbaba , 模版为前8个字符ababbaba, 喷涂的过程为: ababbababbabababbabababbababbaba

输入输出格式

输入格式:

In the first and only line of the standard input there is one word. It is the pattern Byteasar wants painted on his house. It consists of no more than  and no less than  lower-case (non-capital) letters of the English alphabet.

输出格式:

In the first and only line of the standard output one integer should be written - the minimal number of letters in the template.

输入输出样例

输入样例#1:

ababbababbabababbabababbababbaba

输出样例#1:

8

显然通过nxt我们可以找出所有可能的长度,然后从小到大枚举可以拿90分耶!

 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <map>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <queue>
13 #include <time.h>
14 #define eps 1e-7
15 #define INF 0x3f3f3f3f
16 #define MOD 1000000007
17 #define rep0(j,n) for(int j=0;j<n;++j)
18 #define rep1(j,n) for(int j=1;j<=n;++j)
19 #define pb push_back
20 #define set0(n) memset(n,0,sizeof(n))
21 #define ll long long
22 #define ull unsigned long long
23 #define iter(i,v) for(edge *i=head[v];i;i=i->nxt)
24 #define print_runtime printf("Running time:%.3lfs\n",double(clock())/1000.0)
25 #define TO(j) printf(#j": %d\n",j)
26 //#define OJ
27 using namespace std;
28 const int MAXINT = 500010;
29 const int MAXNODE = 100010;
30 const int MAXEDGE = 2*MAXNODE;
31 char BUF,*buf;
32 int read(){
33     char c=getchar();int f=1,x=0;
34     while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
35     while(isdigit(c)){x=x*10+c-'0';c=getchar();}
36     return f*x;
37 }
38 char get_ch(){
39     char c=getchar();
40     while(!isalpha(c)) c=getchar();
41     return c;
42 }
43 //------------------- Head Files ----------------------//
44 int nxt[MAXINT];
45 char s[MAXINT];
46 vector<int> t;
47 void getnxt(){
48     int l = strlen(s);
49     int k=0;
50     for(int i=1;i<l;i++){
51         for(;s[i]!=s[k]&&k;k=nxt[k-1]);
52         if(s[i]==s[k]) k++;
53         nxt[i]=k;
54     }
55 }
56 int test(int len){
57     int l = strlen(s),lpos=-1,k=0;
58     rep0(i,l){
59         for(;s[i]!=s[k]&&k;k=nxt[k-1]);
60         if(s[i]==s[k]) k++;
61         if(k==len) lpos = i,k=nxt[k-1];
62         if(i-lpos>=len) return 0;
63     }
64     return 1;
65 }
66 void get_input();
67 void work();
68 int main() {
69     get_input();
70     work();
71     return 0;
72 }
73 void work(){
74     int l = strlen(s);
75     getnxt();
76     int k = nxt[l-1];
77     while(k){
78         t.push_back(k);
79         k=nxt[k-1];
80     }
81     for(int i=t.size()-1;i>=0;i--){
82         if(t.size()>=1000&&t[i]<=10000) continue;
83         if(test(t[i])) {printf("%d\n",t[i]);return ;}
84     }
85     printf("%d\n",l);
86 }
87 void get_input(){
88     scanf("%s",s);
89 }

少女骗分中

转载于:https://www.cnblogs.com/LoveYayoi/p/7010125.html

洛谷 P3426 [POI2005]SZA-Template相关推荐

  1. 洛谷P3426 [POI2005]SZA-Template 题解

    洛谷P3426 [POI2005]SZA-Template 题解 题目链接:P3426 [POI2005]SZA-Template 题意:你打算在纸上印一串字母. 为了完成这项工作,你决定刻一个印章. ...

  2. 洛谷3426 [POI2005]SZA-Template 恶臭dp+kmp

    前言 做这道题时,我和巨神yxc在洛咕上看到了一篇代码奇短的题解,然后看解析,发现里面的证明都是"显然"."很简单",被臭到. 于是zyd和yxc爆肝了2h左右 ...

  3. 洛谷·[POI2005]SKA-Piggy Banks 小猪存钱罐【Tarjan 并查集

    初见安~这里是传送门:洛谷P3420 题目描述3 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opene ...

  4. P3426 [POI2005]SZA-Template

    洛谷博客链接 P3426 [POI2005]SZA-Template - 传送门 题意 给你一字符串,需要你制作一个印章,能用它盖出该字符串(当然不能多盖). 求最小印章长度. 盖印章: 同一位置,一 ...

  5. Bzoj4016/洛谷P2993 [FJOI2014] 最短路径树问题(最短路径问题+长链剖分/点分治)

    题面 Bzoj 洛谷 题解 首先把最短路径树建出来(用\(Dijkstra\),没试过\(SPFA\)\(\leftarrow\)它死了),然后问题就变成了一个关于深度的问题,可以用长链剖分做,所以我 ...

  6. 记录奥林比克/课程录制 洛谷P2255 [USACO14JAN]

    题面在最下方. 本题贪心可解,我也不是很懂动规解法(双线程DP?) 先把各个课程(比赛)按结束时间从小到大排序,记录两个摄像机的结束时间. 然后枚举课程,如果某个课程的开始时间早于任何一台摄像机的结束 ...

  7. 洛谷P1246C语言,codevs1246 丑数

    题目描述 Description 对于一给定的素数集合 S = {p1, p2, ..., pK}, 来考虑那些质因数全部属于S 的数的集合.这个集合包括,p1, p1p2, p1p1, 和 p1p2 ...

  8. 洛谷 P1063 能量项链 区间dp

    洛谷 P1063 题意:在一串项链中,是环状的,第 i 颗珠子有两个能量a[i]和a[i+1],第i+1颗珠子有两个能量a[i+1]和a[i+2],可以合并两个珠子,得到a[i]*a[i+1]*a[i ...

  9. 洛谷OJ上的A+B花(zhuang)式(bi)解法

    转眼间快到了8月,一想自己都毕业好久了,很怀念曾经在各大OJ上刷题的时光,今天无意在一个算法群里看到最近有个叫洛谷的oj网站貌似蛮火的,于是注册了一个下进去看一看,顺手打开了A+B problem,然 ...

最新文章

  1. MySQL面试题 | 附答案解析(四)
  2. 【Linux驱动】ThinkPad笔记本wifi模块rtl8821ce在ubuntu16.04的驱动(默认没有)
  3. 硕博研究生期间应该明确的50件事
  4. maven netbeans 导入_Maven - NetBeans
  5. 换个姿势学数学:二次函数与拆弹部队
  6. python第四章单元测试_智慧树APPPython语言应用第四单元章节测试答案
  7. static,构造器,执行顺序
  8. 15个问题自查你真的了解java编译优化吗?
  9. python 函数式_10分钟学习函数式Python
  10. Hibernate--fetch=FetchType.LAZY
  11. 为什么越来越多的人直接入住毛坯房?有什么优缺点?
  12. php打开文件对话框,JS打开选择本地文件的对话框
  13. java redis keys_jedis keys和scan操作
  14. oracle sql练习_最方便的在线SQL学习环境——Oracle Live SQL
  15. 当下的力量实践手册读书笔记(1.29)
  16. 计算机游戏设计师要学什么软件,从事游戏设计工作需要学什么专业
  17. 计算机网络图片大全,心情图片大全
  18. Java 矩阵主对角线所有数字之和
  19. 漏洞复现:通过CVE-2022-30190上线CS
  20. 支持图灵架构和安培架构的TensorFlow Python库

热门文章

  1. mac使用my-mind思维导图
  2. listview增大条目间距
  3. 数据挖掘与数据分析项目链家租房数据(三)进一步探索与归纳
  4. 深圳大学计算机与软件学院2018分数线,深圳大学录取分数线2021是多少分(附历年录取分数线)...
  5. 在VMware 14虚拟机下,ndn-cxx和NFD平台搭建
  6. DAMO-YOLO第三方数据训练教程
  7. SAP BTE 增强 物料主数据变更
  8. RMQ倍增,附赠有趣小故事一发
  9. 计算机开机自启文件夹,开机启动文件夹在哪
  10. 问号在c语言里面的作用,问号的作用是什么-写作基础知识