跳到正文

题解

CF2067B Two Large Bags 题解

huanglihuan约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年9月28日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 2 分钟
题目
CF2067B

版本

  1. v1当前

Solution

建一个桶 bb,储存数组 aa,考虑对于 i∈[1,n)i\in[1,n),考虑分讨 bib_i:

  • 对于 bi=1b_i=1,显然无解。
  • 对于 bi=2b_i=2,显然有解(即两袋各一个)。
  • 对于 bi>2b_i>2,可以通过 bi−2b_i-2 次操作二使得 bi=2,bi+1=bi+1+bi−2b_i=2,b_{i+1}=b_{i+1}+b_i-2。

Code

C++
#include <bits/stdc++.h>
#include <cstdio>
#define int long long
#define ull unsigned long long
#define mod 988444333
#define MOD 1000000007
#define in(x,y,z) x>=y&&x<=z
using namespace std;
const int N = 2e6 + 5;
inline int read ()
{
	int x = 0;
	char c = getchar ();
	while (c < '0' || c > '9') c = getchar ();
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48),c = getchar ();
	return x;
}
inline void write (int x)
{
	if (x > 9) write (x / 10);
	putchar (x % 10 + '0');
	return ;
}
void solve ()
{
	int n;
	cin >> n;
	map <int,int> bucket;
	for (int i = 1;i <= n;i ++)
	{
		int x;
		cin >> x;
		bucket [x] ++;
	}
	for (int i = 1;i <= n;i ++)
	{
		if (bucket [i] == 1)
		{
			cout << "NO\n";
			return ;
		}
		else if (bucket [i] > 2) bucket [i + 1] += bucket [i] - 2;
	}
	cout << "YES\n";
}
signed main ()
{
	int T;
	cin >> T;
	while (T --) solve ();
	return 0;
}
原文