HDU 4300 Clairewd's message (KMP)
Question: Give You a conversion table with 26 letters, convert 'A' to the first letter, and convert 'B' to the second... and so on. The second line gives you a ciphertext + plaintext string, and the plaintext may be incomplete, so that you can find the smallest possible solution.
Train of Thought: the train of thought is not difficult to think about, it is to convert the ciphertext into plain text, and then start to KMP the original string from the middle until the last character returns the matching length. The matching length is the shortest plaintext length.
For details, see the code:
#include
#include
#include#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;typedef long long ll;typedef long double ld;const ld eps = 1e-9, PI = 3.1415926535897932384626433832795;const int mod = 1000000000 + 7;const int INF = 0x3f3f3f3f;// & 0x7FFFFFFFconst int seed = 131;const ll INF64 = ll(1e18);const int maxn = 1000000 + 10;int n,t,m,f[maxn],ans;char s[maxn],T[maxn];void getfail(char *p, int m) { f[0] = f[1] = 0; for(int i=1;i