跳到正文

题解

题解:P14292 [JOI2024 预选赛 R2] 卡牌游戏 / Card Game 2

Na1L0n9约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年10月22日
收录
2026年8月9日
更新
2026年11月13日
篇幅
约 1 分钟
题目
P14292

版本

  1. v1当前

Solution

思路

考虑枚举每一张卡片并尝试将其作为合法方案中最小的卡片,设我们所枚举的卡片上的数字为 xx,只要找到卡片序列中是否出现 x+3x+3 和 x+6x+6 即可,直接暴力枚举的时间复杂度是 O(n2)O(n^2),显然无法通过,注意到 AiA_i 的范围很小,用一个桶预处理出有哪些牌出现过即可。

Code

C++
#include <bits/stdc++.h>
#define Write ios::sync_with_stdio(0);
#define by cin.tie(0);
#define Na1L0n9 cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5 + 10;
const int MOD = 998244353;
int n, a[N], cnt[N];
bool vis[N];
int main() {
	Write by Na1L0n9
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		vis[a[i]] = 1;
	}
	for (int i = 1; i <= n; i++) {
		if (vis[a[i] + 3] && vis[a[i] + 6]) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}
原文