跳到正文

题解

题解:CF488B Candy Boxes

qazabcdef1111约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月6日
篇幅
约 3 分钟
题目
CF488B

版本

  1. v1当前

我们注意到 x1,x2,x3,x4x1,x2,x3,x4 存在的充要条件是存在 S∈Z,D≤S2S\in \Z,D\le \frac{S}{2},使得 x1=S2,x2=S−D,x3=S+D,x4=3S2x1=\frac{S}{2},x2=S-D,x3=S+D,x4=\frac{3S}{2}。

发现值域很小,直接做就好了。

C++
#include <bits/stdc++.h>
#define lb(x) (x&-x)
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)

using namespace std;
using i64 = long long;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
void chmin(int &x, int c) {x = min(x, c);}
void chmax(int &x, int c) {x = max(x, c);}

const int maxn = 3e5 + 10, mod = 998244353;
int N, A[maxn], cnt[maxn];

void solve() {
	cin >> N;
	L (i, 1, N) cin >> A[i];
	for (int S = 2; S <= 1000; S += 2) {
		for (int D = 0; D <= S / 2; D ++ ) {
			L (i, 1, N) cnt[A[i]] ++;
			vector<int> res; res.clear();
			if (cnt[S / 2] == 0) {
				res.push_back (S / 2);
			} else cnt[S / 2] -- ;
			if (cnt[3 * S / 2] == 0) {
				res.push_back (3 * S / 2);
			} else cnt[3 * S / 2] -- ;
			if (cnt[S - D] == 0) {
				res.push_back (S - D);
			} else cnt[S - D] -- ;
			if (cnt[S + D] == 0) {
				res.push_back (S + D);
			} else cnt[S + D] -- ;
			if ((int)res.size() == 4 - N) {
				cout << "YES\n";
				for (int x : res) cout << x << '\n';
				return ;
			}
			L (i, 1, N) cnt[A[i]] = 0;
		}
	}
	cout << "NO\n";
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--)solve();
  return 0;
}
// 常年玩柚子社的人都目光炯炯有神,非常自信,且智商逐年上升,最后完全成为天才。
// 玩柚子社会改造身体结构,预防各种不治之症。
// 人一旦开始玩柚子社就说明这个人的智慧品行样貌通通都是上等,这辈子都能在任何地方风姿飒爽。
// 柚子厨具有强烈的社会正义感,对治安稳定有巨大的贡献,保护普通人的生命。
原文