https://www.nowcoder.com/acm/contest/134/I
这是一道我打BUG打得颠狂地笑出来的题(其实是笑自己神经病)
题解:
1、统计妹子个数,放置后期处理溢出
2、给序列上的每个点染色(染成所属最长妹子序列长度)
3、对于每个男生点,判断两边颜色相加再+1,注意和妹子总数比较维护最小值,最长序列维护最大值就是答案
4、(颠狂点)边界情况,全是妹子,或者全是单身狗,或者嘴边上一个狗,其他全是妹子等情况。疯狂打补丁,颠狂地笑。
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
string str;
cin >> n;
cin >> str;
int tag = 0,res = 0,ma = 0;
for(int i = 0;i < n;i++) {
if(str[i] == '0') {
a[i] = tag + 1;
tag++;
res++;
}
else tag = 0;
}
for(int i = n - 1;i >= 0;i--) {
if(a[i] == 0)
tag = 0;
else {
tag = max(tag,a[i]);
a[i] = max(tag,a[i]);
}
}
for(int i = 1;i < n - 1;i++) {
if(str[i] == '1') {
int cnt = a[i-1] + 1 + a[i+1];
ma = max(cnt,ma);
if(ma > res) ma = res;
}
}
if(str[0] == '1') {
int cnt = 1 + a[1];
ma = max(cnt,ma);
if(ma > res) ma = res;
}
if(str[n-1] == '1') {
int cnt = a[n-2] + 1;
ma = max(cnt,ma);
if(ma > res) ma = res;
}
if(res == n) cout << n << endl;
else cout << ma << endl;
return 0;
}