CF1802B 题解

思路

首先我们要把当前的猪分成两类——有性别和无性别。无性猪只能一猪一笼,有性别时最坏情况下是 s2+1\lfloor\frac s2\rfloor+1 个笼(没有有性猪时要特判)。需要的笼子就是它们之和。

代码

# include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int t, n, x, sum, tot, maxx;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> t;
	while (t --) {
		cin >> n;
		maxx = sum = tot = 0;
		for (int i = 0; i < n; ++ i) {
			cin >> x;
			if (x < 2)
				++ tot;
			else
				sum += tot, tot = 0;
			maxx = max (maxx, (sum >> 1) + tot + (sum > 0));
		}
		cout << maxx << '\n';
	}
	return 0;
}
posted @   sz_jinzikai  阅读(1)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示