A. Sushi for Two

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int N, cnt = ;
int a[maxn], vis[maxn]; int main() {
scanf("%d", &N);
for(int i = ; i <= N; i ++)
scanf("%d", &a[i]); int l = , r = ;
while(l <= N && r <= N) {
while(a[l] == a[r] && r <= N) vis[cnt] ++, r ++;
cnt ++;
l = r;
} int maxx = ;
for(int i = ; i < cnt - ; i ++) {
int t = min(vis[i], vis[i + ]);
maxx = max(t * , maxx);
} printf("%d\n", maxx);
return ;
}

B. Circus

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + ;
int N;
string s, t;
int A, B ,C, D;
int a, b, c, d; int main() {
scanf("%d", &N);
cin >> s >> t;
for(int i = ; i < N; i ++) {
if(s[i] == '') {
if(t[i] == '') A ++;
else B ++;
} else {
if(t[i] == '') C ++;
else D ++;
}
} bool flag = false;
for(a = ; a <= A && a <= N / ; a ++) {
int t1 = a + B + D - N / ;
if(t1 >= && t1 <= N / && t1 <= D) {
d = t1; for(b = ; b <= B && b <= N / ; b ++) {
int t2 = N / - a - b - d;
if(t2 >= && t2 <= C && t2 <= N / ) {
c = t2;
flag = true;
break;
}
}
if(flag) break;
}
} if(flag) {
vector<int> ans;
for(int i = ; i < N; i ++) {
if(s[i] == '') {
if(a && t[i] == '') {
ans.push_back(i + );
a --;
} else if(b && t[i] == '') {
ans.push_back(i + );
b --;
}
} else {
if(c && t[i] == '') {
ans.push_back(i + );
c --;
} else if(d && t[i] == '') {
ans.push_back(i + );
d --;
}
}
} for(int i = ; i < ans.size(); i ++)
printf("%d%s", ans[i], i != ans.size() - ? " " : "\n"); } else printf("-1\n"); return ;
}

D. Camp Schedule

D 很简单的 KMP 求出来 nx[t.length()] 然后求出来最小循环节 先把最小循环节前面的部分输出然后输出最小循环节最后把剩下的输出 我是。。真滴不想写了

05-11 04:48