原题链接:https://codeforces.com/problemset/problem/1141/B
题意:给定一个序列,女孩每次都会重复这个序列做事情,让我们寻找有多少个连续的1。
解题思路:注意是周期,我们要开两倍大的数组存放着重复的序列,再遍历一遍数组找出最多有多少个重复的1即可。
AC代码:
/*
*/
//低版本G++编译器不支持,若使用这种G++编译器此段应注释掉
//i为循环变量,a为初始值,n为界限值,递增
//i为循环变量, a为初始值,n为界限值,递减。
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll inf = 0x3f3f3f3f;//无穷大
const ll maxn = 4e5+2;//最大值。
//*******************************分割线,以上为代码自定义代码模板***************************************//
bool nums[maxn];
int n;
int maxx;
int sum;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
ios::sync_with_stdio(false);//打消iostream中输入输出缓存,节省时间。
cin.tie(0); cout.tie(0);//可以通过tie(0)(0表示NULL)来解除cin与cout的绑定,进一步加快执行效率。
while(cin>>n){
rep(i,0,n-1){
cin>>nums[i];
nums[i+n]=nums[i];
}
sum=0;maxx=0;
rep(i,0,2*n-1){
if(nums[i]!=0){
sum++;
}
else{
if(maxx<sum){
maxx=sum;
}
sum=0;
}
}
cout<<maxx<<endl;
}
return 0;
}