Atoder-3620】的更多相关文章

最近感到KMP不会啊,以前都是背板的现在要理解了. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; ; char S[Maxn]; int k,P[Maxn],Ans; inline void Kmp(char * Str) { ; ;Str[i];i++) { ]!=Str[i] && j)…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3620 [题意] 给定一个字符串,统计有多少形如A+B+A的子串,要求A>=K,B>=1. [思路] 枚举左端点i,对字符串s[i..n]统计答案. 放个指针,然后枚举右端点j,如果指针超过长度一半则沿fail向前找,设指针为k.如果匹配则满足s[i..k]==s[j-k+1..j],最后判定一下长度限制. [代码] #include<cstdio> #include&l…
题目链接:BZOJ - 3620 题目分析 这道题使用 KMP 做 O(n^2) 的暴力就能过. 首先,我们依次枚举字串左端点 l ,然后从这个左端点开始向后做一次 KMP. 然后我们枚举右端点 r ,符合条件的右端点 r 就是 S[l..r] 这一段的一个前缀和后缀相同,并且这一部分的长度 x 要满足 k <= x < (r - l + 1) / 2. 我们就使用 KMP 的 Next 数组来找这个前缀,直接从 Next[r] 向前找最坏情况会导致变成 O(n^3) ,所以我们应该优化一下:…
十分暴力的KMP,枚举左端点,在向右侧推进的同时,取较小的la保证条件,n方暴力 #include<bits/stdc++.h> #define rep(i,j,k) for(int i=j;i<=k;i++) #define inf 0x3fffffff using namespace std; ; char s[N];int l,k,nxt[N],la[N],ans; int main(){ freopen("3620.in","r",stdi…
3620: 似乎在梦中见过的样子 Time Limit: 15 Sec  Memory Limit: 128 MBSubmit: 755  Solved: 445 Description “Madoka,不要相信 QB!”伴随着 Homura 的失望地喊叫,Madoka 与 QB 签订了契约. 这是 Modoka 的一个噩梦,也同时是上个轮回中所发生的事.为了使这一次 Madoka 不再与 QB签订契约,Homura 决定在刚到学校的第一天就解决 QB.然而,QB 也是有许多替身的(但在第八话中…
http://poj.org/problem?id=3620 DFS 从任意一个lake出发 重置联通的lake 并且记录 更新ans #include <iostream> #include <string.h> #include <stdio.h> using namespace std; int N,M,K; ][]; ][] = {-, , , , , , , -}; ; ; bool OK(int x, int y) { || x > N || y &l…
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3620 [算法] KMP [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 15010 int i,len,k,ans; char s[MAXN]; inline void kmp(int pos) { int i,j,tmp; static int nxt[MAXN]; nxt[pos] = ; ; i…
Avoid The Lakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 4270 Description Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of wate…
题目 找最大的一片湖的面积,4便有1边相连算相连,4角不算. runtime error 有一种可能是 数组开的太小,越界了 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<queue> using namespace std; #define MAXN 110 in…
题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home again. The fire can destroy all the things in t seconds, so LTR has to escape in t seconds. But there are some jewels in LTR ' s rooms, LTR love jewe…