B. Settlement of Guinea Pigs

原题

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.

详见Problem - B - Codeforces

题目大意:

输入为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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值