#include<bits/stdc++.h>using namespace std;const int N=1000007;char s1[N],s2[N];int len1,len2;int nex[N];int cnt1[7],cnt2[7];int main(){    scanf("%s %s",s1+1,s2+1);    len1=strlen(s1+1);    len2=strlen(s2+1);    for(int i=1;i<=len1;i++…
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn(1005); int n, m, a[maxn][maxn], mx1[maxn][maxn], mx2[maxn][maxn], q[maxn], len; int main() { i…
题意是在所给的两个字符串中找最长的公共前后缀,即第一个字符串前缀和第二个字符串后缀的最长相等串. 思路是将两个字符串拼接在一起,然后直接套用 kmp 算法即可. 要注意用 next 会报编译错误,改成 Next 才过……但 next 确实不是 c++ 关键字. 代码如下: #include <iostream> #include <cstring> #include <cstdio> using namespace std; +; ],b[N]; ]; void get…
http://poj.org/problem?id=2752 [题意] 给定一个字符串,求这个字符串的所有公共前后缀的长度,按从小到达输出 [思路] 利用kmp的next数组,最后加上这个字符串本身 [AC] #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> using namespace std; typedef…
https://codeforces.com/contest/1138/problem/D 题意 两个01串s和t,s中字符能相互交换,问最多能得到多少个(可交叉)的t 题解 即将s中的01塞进t中,预处理出next(tlen),然后每次填完移到next(tlen)继续填即可 代码 #include<bits/stdc++.h> using namespace std; int sl,pl,i,j,a,b,e,f,nt[500005]; string s,p; void get_nt(){ i…
人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscrapers 将行列各自离散化并记录下每一个值在行离散化时和列离散化时得到的值以及每一行.每一列出现的最大离散化值 对于每一行和每一列考虑其相交格子的两个离散化值,如果它们的差为\(\Delta\),就把它对应行列最大离散化值中较小的+\(\Delta\),最后两者取Max #include<iostream…
题目要求,给定一个s序列,一个p序列,问能不能对s做相应的调整,使得s序列中,有尽可能多的p子串(可以重复) 最开始我拿到这个题目,也是一点头绪都没有,如何做调整呢? 首先考虑如何会有尽可能多的子串,可以相交那种? 貌似我们要找的就是子串后缀和前缀匹配度 这里再次补充一下KMP中next数组的意义 首先要理解next数组的含义:https://www.cnblogs.com/chenxiwenruo/p/3546457.html 那么我们通过求next数组,很容易知道知道,t的最小循环长度是k=…
A. Sushi for Two 代码: #include <bits/stdc++.h> using namespace std; ; ; int a[maxn], vis[maxn]; int main() { scanf("%d", &N); ; i <= N; i ++) scanf("%d", &a[i]); , r = ; while(l <= N && r <= N) { while(a[l…
A:求出该行该列各有多少个比其小的取max,该行该列各有多少个比其大的取max,加起来即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 1010 char ge…
链接:http://codeforces.com/contest/1138/problem/D 啊啊啊啊啊啊,自闭啊,比赛的时候判断条件 if(s1[i-1]=='0') aa++;写成了 if(s1[i]=='0') aa++;少写了个-1,被hack了,上分场变成了掉分场. 思路; 题目需要t字符串出现次数最多,那么找到最大的重叠部分就好了,然后依次加上就好了 主要就是要找到字符串t与本身的重叠部分,,假设有两个t,第一个t不变,第二个t向右移动: 比如: 10101010 -1010101…