原题
Dasha loves guinea pigs very much. In this regard, she decided to settle as many guinea pigs at home as possible and developed a plan for the next n days. Every day, she will either buy a new guinea pig or call a doctor to examine all her pets.
Unfortunately, the store where she was going to buy guinea pigs does not understand them. Therefore, it cannot determine their gender. Dasha can't do it either. The only one who can help is a doctor.
To keep guinea pigs, aviaries are needed. Dasha plans to buy them in the same store. Unfortunately, only one species is sold there — a double aviary. No more than two guinea pigs can live in it.
Since Dasha does not want to cause moral injury to her pets — she will not settle two guinea pigs of different genders in one aviary.
Help Dasha calculate how many aviaries in the worst case you need to buy so that you can be sure that at no moment of time do two guinea pigs of different genders live in the same aviary.
As part of this task, we believe that guinea pigs have only two genders — male and female.
Input
The first line of input data contains one number t (1⩽t⩽1051⩽105) — the number of input data sets.
The first line of each input data set contains one number n(1⩽n⩽1051⩽⩽105) — the number of days Dasha has a plan for.
The next line contains n numbers b1,b2,b3,…,bn1,2,3,…,(1⩽bi⩽21⩽2) — Dasha's plan. If bi=1=1, then on the ith day, Dasha will buy a new guinea pig. If bi==2, then on the i th day, a doctor will come to Dasha and help determine the sex of all guinea pigs that Dasha already has.
It is guaranteed that the sum of n for all input data sets does not exceed 105105.
Output
For each set of input data, output one number — the minimum number of aviaries Dasha needs to buy so that no matter what the genders of the pigs turn out to be, we can settle them so that at no point in time do two guinea pigs of different genders live together.
题目大意:
输入为1时购进小动物(我也不知道啥动物),雌雄两只为一笼,购买时不知雌雄
当输入为2时,判断出动物的雌雄,雌雄一笼(此时数量/2向上取整即可);
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n,sum=0,ss=0,ans=0;// ans 鼠笼 ss 鼠鼠啊
cin >> n;
for(int i=1;i<=n;i++)
{
int te;
cin >> te;
if(te==1)
{
sum++;
ss++;
int num = 0;
if(ss != sum && (ss-sum)%2 != 0)
num = (ss-sum)/2+1;
else if(ss != sum) num = (ss-sum-1)/2+2;
ans = max(ans,num+sum);
}
else
{
sum=0;
int num=0;
if(ss!=0 && ss%2 != 0)
num=ss/2+1;//现笼子量
else num = (ss+1)/2;
ans = max(ans,num);
}
}
cout << ans<< endl;
return;
}
int main()
{
int t;
cin >> t;
while(t--)
solve();
return 0;
}