电影院选座
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
using namespace std;
typedef long long ll;
const int maxn=5010;//数组所开最大值
const int mod=1e9+7;//模
const int inf=0x3f3f3f3f;//无穷大
int main()
{
int nums[20010];
int n = 0;
char c;
while((c=getchar())!='\n')
{
if(c>='0'&&c<='9')
{
ungetc(c,stdin);
cin>>nums[n++];
}
}
int cnt = 0;
int res = 0;
int s = 0;
int e = 0;
for(int i = 0; i < n; i ++)
{ s = min(i,s);
if(nums[i] == 0)
{
cnt ++;
}
else
{
e = i;
if(nums[s] == 1 && nums[e] == 1){
if(cnt >= res){
///0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0
int temp = cnt + 2;
if(temp % 2 == 0)
temp = temp / 2 -1;
else
temp = temp / 2;
res = max(res,temp);
}
}
else{
res = max(res,cnt);
}
cnt = 0;
s = i;
}
}
//0 0 0 1 0 0 0 1 0 0 0 0
res = max(res,cnt);
cout <<res << endl;
}
腾讯成长空间 5933人发布