题目:https://codeforc.es/contest/1200/problem/E 题意:给你n个单词,你需要把他合成成一个句子,相邻的两个单词,相邻部分相同的话可以把其中一个的删掉 思路:因为这个串总共加起来<=1e6 ,所以我们能接受O(n)每个字母的复杂度,我们直接遍历求出每个前缀后缀的哈希值,然后找到最长即可,唯一要注意的是因为是在cf上的题,必须要写双哈希 #include<bits/stdc++.h> #define maxn 1000005 #define mod…
Codeforces Round #578 (Div. 2) 传送门 A. Hotelier 暴力即可. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 5; int n; char s[N]; int res[10]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n;…
题目链接:https://codeforc.es/contest/1200/problem/E 题意: 有n串字符串,让你连起来:sample please ease in out   ---> sampleaseinout 思路: 肯定KMP啊,但是比赛的时候对kmp的next数组一知半解,所以也不知道怎么用. next数组其实就是对key串进行处理next(失配值),然后在母串上去匹配. #define IOS ios_base::sync_with_stdio(0); cin.tie(0)…
Problem A Hotelier 直接模拟即可~~ 复杂度是$O(10 \times n)$ # include<bits/stdc++.h> using namespace std; ; char s[N]; ]; int main() { int n; scanf("%d",&n); scanf("%s",s); ;i<n;i++) { if (s[i]=='L') { ;j<=;j++) if (!a[j]) { a[j]=…
题意: 在n*n的矩阵中,你可以选择一个k*k的子矩阵,然后将这个子矩阵中的所有B全部变为W,问你怎么选择这个子矩阵使得最终的矩阵中某一行全是W或者某一列全是W的个数最多 题解:考虑每一行和每一列,对于特定的一行来说,要想让其全变为W,那么子矩阵的左上角端点是在一个范围中的,因此我们可以把范围中的每一个值加1 为了速度选择用二维差分来做,最终矩阵中的最大值就是答案 此题可以作为二维差分模板 #include<bits/stdc++.h> #define forn(i, n) for (int…
题意: 有一个分两层的圆盘,每层从12点方向均分插入\(n\)和\(m\)个隔板,当内层和外层的隔板相连时是不能通过的,有\(q\)个询问,每次给你内层或外层的两个点,判断是否能从一个点走到另外一个点. 题解: 因为是均分,所以内层和外层隔板相连的个数为\(gcd(n,m)\),不懂的可以从角度方向来考虑,将\(360\)度分成\(n\)和\(m\)个\(360/n\)度和\(360/m\)度,不难看出是gcd,接下来的就好搞了,从整体上看,我们将这个大圆分成了\(gcd(n,m)\)块,所以我…
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2. 压缩一个串,条件是这个串是前面整个串的连续子串,代价为b 题解 n<=5000 定义dp[i]为压缩前i个字符的代价,则答案为dp[n] dp[i]=min(dp[i-1]+a,min(dp[j]+b)(即[j+1,i]为[1,j]的子串)) 用字符串哈希处理判定一个串是否为前面的子串 坑点 串ab…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…