牛客练习赛42
题目链接https://ac.nowcoder.com/acm/contest/393#question
A-字符串
这题只要找两个字符串公共最长子串就好了,O(n)
其中LCS=LCP=最长公共子串
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<stack> #include<cstdio> #include<cmath> #include<queue> #include<cstring> #include<string> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 200000+10; const int inf = 0x7fffffff; const int mod = 100000007; //========================== string a, b; int n; int main() { cin >> a >> b; int res = 0,t=0; for (int i = 0; i <a.length() ; i++){ //cout << a[i] << "--" << b[i] << endl; if (a[i] - b[i]==0){ t++; //cout << i << endl; } else { res = max(res, t); t = 0; } } cout << 1ll*res*res+1ll*2*res << endl; return 0; }
B-SHTMYCBDFTT
直接模拟就好了,O(n),注意取模
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<stack> #include<cstdio> #include<cmath> #include<queue> #include<cstring> #include<string> #include<algorithm> using namespace std; typedef long long ll; const int maxn = 3e5+10; const int inf = 0x7fffffff; const int mod = 100000007; //========================== ll a[maxn]; int n; int main() { ios::sync_with_stdio(false); cin >> n; ll ans1 = 0,ans2=0; for (int i = 0; i < n; i++){ cin >> a[i]; ans1 ^= a[i]; ans2 += a[i]; ans2 %= mod; } cout << (ans1 + ans2)%mod << endl; return 0; }