2021-08-20 AcWing 3810. 最长连续休息时间
输入样例:
4
5
1 0 1 0 1
6
0 1 0 1 1 0
7
1 0 1 1 1 0 1
3
0 0 0
输出样例:
2
2
3
0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 400010;
vector<int> a(N);
int main()
{
int t,n;
cin >> t;
while(t--)
{
cin >> n;
int cnt=0;
int maxx=-1;
for (int i = 0; i < n; i ++ )
{
scanf("%d", &a[i]);
a[n+i]=a[i];
}
for (int i = 0; i < 2*n; i ++ ){
if(a[i]){
cnt++;
}else{
cnt=0;
}
maxx = max(cnt,maxx);
}
cout <<maxx << endl;
}
return 0;
}
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/15799131.html