Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings: String Rank SKYLONG 1 KYLONGS 2 YLONGSK 3 LONGSKY 4 ONGSKYL 5 NGSKYLO 6 GSKYLON 7 and lexicograp…
hdu 3374 String Problem 最小表示法 view code#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <string> using namespace std; const int N = 10010; int n; char s[105]; map<…
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1602    Accepted Submission(s): 714 Problem Description Give you a string with length N, you c…
Problem Description Give you a string with length N, you can generate N strings by left shifts. For example let consider the string “SKYLONG”, we can generate seven strings:String Rank SKYLONG 1KYLONGS 2YLONGSK 3LONGSKY 4ONGSKYL 5NGSKYLO 6GSKYLON 7an…
做一个高产的菜鸡 传送门:HDU - 3374 题意:多组输入,给你一个字符串,求它最小和最大表示法出现的位置和次数. 题解:刚刚学会最大最小表示法,amazing.. 次数就是最小循环节循环的次数. #include<bits/stdc++.h> using namespace std; int nt[1000100],b[1000100]; char a[1000100]; void kmp_nt(int m) { int i,j; i = 0; nt[0] = j =-1; while(…
题意: 给出一个字符串,问这个字符串经过移动后的字典序最小的字符串的首字符位置和字典序最大的字符串的首字符的位置,和能出现多少次最小字典序的字符串和最大字典序的字符串 解析: 能出现多少次就是求整个字符串能出现几次循环 然后就是最大最小表示法..有点厉害... #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #in…
String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2706    Accepted Submission(s): 1140 Problem Description Give you a string with length N, you can generate N strings by left shift…
最大最小表示法与KMP求循环节 最大最小表示法 最大最小表示法与KMP求循环节的模板题, #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; const int MAXN=2000005; int init(){ int…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:输出最大和最小的是从哪一位开始的,同时输出最小循环节的个数. 这里简单介绍对字符串最小表示的方法: (1)  利用两个指针p1, p2.初始化时p1指向s[0], p2指向s[1]. (2)  k = 0开始,检验s[p1+k] 与 s[p2+k] 对应的字符是否相等,如果相等则k++,一直下去,直到找到第一个不同,(若k试了一个字符串的长度也没找到不同,则那个位置就是最小表示位置,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给出一个字符串问这个字符串最小表示的最小位置在哪,还有有几个最小表示的串.最大表示的位置在哪,还有有几个最大 表示的串. 题解:就是最小表示求一下,最大表示求一下,然后在kmp计数一下就行.注意最小表示和最大表示求的时候一定要 增倍字符串. #include <iostream> #include <cstring> #include <cstdio> usin…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3374 [题目大意] 给出一个字符串,求出最小和最大表示是从哪一位开始的,并且输出数量. [题解] 最小最大表示可以用最小最大表示法解决,数量则可以发现就是该字符串的循环节,可以用nxt数组求解. [代码] #include <cstring> #include <cstdio> #include <algorithm> const int N=1000010; usin…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:给出一个字符串,依次左移一个单位形成一堆字符串,求其字典序最小和最大的字符串需要左移多少位,以及一共有几个这样的字符串(例如0101->1010->0101). 解题思路:首先可以确定两个字符串出现的次数应该相同,即循环节数目,这个比较容易得到.然后就是最大最小字符串如何得到的问题了,直接暴力肯定超时.... 所以这里找到了比较好的方法,转载:http://blog.csdn.ne…
Problem - 3374   KMP求循环节. http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html   循环节推导的证明相当的好,这题是很裸的套算法的题. 代码如下: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; ; char buf…
题意:给你一个字符串,这个字符串可以这样操作:把第一个字符放到最后一个形成一个新的字符串,记原式Rank为1,每操作一步Rank+1,问你这样操作得出的最小字典序的字符串的Rank和这样的字符串有几个,最大字典序的字符串的Rank和这样的字符串有几个. 思路:手动模拟操作复杂度O(n^2)果断超时,引入一种专门计算此情况的方法,复杂度O(n). 这里只说最小表示: 我们先拿两个指针i,j,分别指向s[0],s[1],将k初始化为0.然后我们循环计算s[i + k]是否等于s[j + k],直到找…
KMP,在有循环节的前提下: 循环节 t = len-next[len], 个数num = len/(len-next[len]);个人理解,如果有循环节,循环节长度必定小于等于len/2, 换句话说next[len]>=len/2;对于len%(len-next)!=0的这种情况不讨论,循环节不存在.下面是假设循环节存在的情况当次数等于2, 对于abcabc这种情况就不用说了,len = 6, next[len] = 3;当次数大于2,对于串a1 a2 a3 a4 a5 a6 a7 a8 a9…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.   Input The first line of inp…
今天又在lyk大佬的博客学会了——最小表示法(异常激动发篇题解纪念一下说在前面:给luogu提个建议最小表示法的题太少了,都被hdu抢去了!!! 我们先看一下题目 看完后可以用一个字概括——蒙,两个字——懵逼 在这里我提供题目大意: 输出最大和最小的是从哪一位开始的,同时输出最小循环节的个数. 由于本人懒于写字符串最小表示法,那么我们就来借鉴一下lykkk的优秀总结 看完之后,显然我们就明白了许多 因为题目中让我们同时求出最大和最小的起始位置 所以我们不仅要来一遍最小表示法,还要来一遍最大表示法…
题目链接:https://vjudge.net/problem/HDU-3374 String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3646    Accepted Submission(s): 1507 Problem Description Give you a string with length N,…
https://konnyakuxzy.github.io/BZPRO/JudgeOnline/2740.html 题解讲的很清楚了 (好像等于的情况应该归入case2而不是case1?并不确定) 具体方法: 将串翻转,找到字典序最小且最短的后缀,然后找到以这个后缀为纯循环节的最长后缀T,则第一步是将这个后缀T提到最前面: 然后第二步是把整个串除T外部分变为其循环同构串的最小表示. 要找到字典序最小且最短的后缀,只要找到整个串的最小表示法(设最小表示法在位置i开始),然后找到S[i..n]的最短…
链接: https://vjudge.net/problem/HDU-3374 题意: Give you a string with length N, you can generate N strings by left shifts. For example let consider the string "SKYLONG", we can generate seven strings: String Rank SKYLONG 1 KYLONGS 2 YLONGSK 3 LONGS…
传送门:https://ac.nowcoder.com/acm/contest/887/A 题意:大意就是给你一个只含有0和1的字符串,找出一种分割方法,使得每个分割出的字符串都是在该字符串自循环节中最小 思路: 一: 最小表示法的模板题了,数据范围比较小.每次枚举字符串的最长长度,用最小表示法进行判断即可. 最小表示法的介绍:https://oi-wiki.org/string/minimal-string/ 代码: #include<bits/stdc++.h> using namespa…
最小标示法:给定一个字符串,不断将其最后一个字符放到开头,最终会得到n个字符串,称这n个字符串循环同构,这些字符串中字典序最小的一个,就是最小表示法 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define maxn 1000005 int len; int main(){ int t; cin>>t; while(t--){ ]={}; cin>…
String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple problem about string. Now a string S contains only '0'-'9'. ?? wants to select a subsequence from this string. And makes this subsequence score maximum.…
http://acm.hdu.edu.cn/showproblem.php?pid=3549 刚接触网络流,感觉有点难啊,只好先拿几道基础的模板题来练练手. 最大流的模板题. #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<queue> using namespace std; int n, m, flow; ]; //路径记录…
String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3183    Accepted Submission(s): 1295 Problem Description Give you a string with length N, you can generate N strings by left shifts…
一开始没太看懂什么意思,拿笔反复推了一遍才大概知道最大最小表示法是怎么求的,感觉太神奇了... #include <iostream> #include <cstdio> #include <string.h> #pragma warning ( disable : 4996 ) using namespace std; inline int Max(int a,int b) { return a>b?a:b; } inline int Min(int a,int…
题目大意: 与别的裸题的唯一不同点是其符号的ASCII码值在3 ~ 254 之间. 算法讨论: 最小表示法直接上.但是唯一不同的就是注意这里的字符范围,用char是会get wa的,所以要用unsigned char.这两者的区别就是可以表示的ASCII范围不同. char是有符号位的,其可以表示的范围是-128~127, 而unsigned char 可以表示的范围是 0~ 255. 至于输入输出,和原来是一样的.只改一个关键字即可. 不贴代码了.…
*N]; //储存临时串 *N];//中间记录 int Manacher(char tmp[]) { int len=strlen(tmp); ; ;i<len;i++) { s[cnt++]='#'; s[cnt++]=tmp[i]; } s[cnt++]='#'; memset(save,,sizeof(save)); ,p=; ; ;i<cnt-;i++) { if(i>=p) { ; &&s[i+num]==s[i-num]) { num++; } p=i+num…
最小表示法就是一个字符串构成一个环,找以哪个点为开头字典序最小. 然后我们就可以用n2的算法愉快的做啦~实际上有O(n)的做法的,就是用两个指针扫,如果这两个位置的字典序相等,就一起往后,如果某一个大,就把那个指针指到大的那个的后面. 每次至少有一个指针往后移一个,复杂度就是线性的了. (自己YY的,求不出锅) #include <iostream> #include <cstdio> #include <cstring> using namespace std; in…
本文参考: https://www.cnblogs.com/GerynOhenz/p/8727415.html kuangbin的ACM模板(新) 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4347 Problem Description The course of Software Design and Development Practice is objectionable. ZLC is facing a serious problem…