2011: Mex Query

博客内容讲述了作者在解决2011年一个编程竞赛题'Mex Query'时遇到的理解误区和解题过程。作者最初因误解题意陷入困境,后来通过排序和优化策略解决了问题,强调正确理解题意的重要性,并分享了从失败中吸取的经验教训。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2011: Mex Query

描述
题目描述:

Give nn non-negative integers, please find the least non-negative integer that doesn’t occur in the nn numbers.

输入:

The first line is an integer TT, representing the number of test cases.

For each test case:

The first line of each te

<think>Hmm, the user query "serval and final mex" seems ambiguous at first glance. The term "serval" could refer to the wild cat species, while "final mex" might be a misspelling or abbreviation of "final MEX" in mathematics. Given the lack of clear context, it's necessary to investigate both possibilities. For "serval", the biological interpretation is straightforward - it's a medium-sized African wild cat. But "final mex" requires more careful analysis since it could relate to combinatorial game theory or competitive programming concepts. The mathematical angle appears more probable in a technical context. MEX stands for Minimum Excluded Value, a fundamental concept in game theory and algorithm design. The "final mex" likely refers to the last MEX value computed in a sequence or game state. Search results confirm this interpretation. Multiple programming resources discuss calculating MEX values in arrays, especially for Nim game variants. The key insight is that final MEX determines winning positions in impartial games. For clarity, the response should: - First disambiguate "serval" as the animal - Then focus on "final mex" as the mathematical concept - Provide formal definition with proper LaTeX formatting - Include a Python implementation example - Explain its significance in game outcomes The user might be preparing for programming competitions or studying game theory. The related questions should therefore explore both the biological curiosity about servals and deeper applications of MEX in algorithms. Potential pitfalls to avoid: - Don't merge the two unrelated topics (animal vs math) - Ensure code examples are correctly formatted - Verify mathematical notation renders properly - Keep related questions focused yet distinct</think>基于网络搜索,"serval" 和 "final mex" 涉及两个不同领域的概念,需分别解释: ### 一、Serval(非洲薮猫) - **生物学特征**:中型野生猫科动物(*Leptailurus serval*),分布于撒哈拉以南非洲。 - **识别特征**: - 体型修长,腿长比例猫科第一 - 金黄色皮毛带黑色斑点条纹 - 耳廓巨大(高度约8cm),可独立旋转定位猎物 - **生态地位**: - 顶级捕食者,控制啮齿类动物数量 - 受栖息地丧失威胁,CITES附录Ⅱ保护物种 ### 二、Final MEX(数学/编程概念) **MEX(Minimum Excluded Value)** 指集合中未出现的最小非负整数。**Final MEX** 特指序列操作后的最终MEX值,常见于算法竞赛。 #### 计算示例 给定数组 `[0, 2, 2, 3]`: 1. 存在数字:0, 2, 3 2. 缺失的最小非负整数:1 3. $\text{MEX} = 1$ #### 典型应用场景 - **Nim游戏变体**:Final MEX决定必胜/必败态 - **数组重构问题**:通过操作使数组MEX达到目标值 #### Python实现MEX计算 ```python def compute_mex(arr): n = len(arr) # 标记0到n范围内存在的数字 present = [False] * (n + 1) for num in arr: if 0 <= num <= n: present[num] = True # 返回最小缺失值 for i in range(n + 1): if not present[i]: return i return n + 1 # 示例 arr = [0, 2, 2, 3] print(compute_mex(arr)) # 输出: 1 ``` #### 关键公式 MEX的数学定义: $$\text{MEX}(S) = \min \{ k \in \mathbb{N}_0 \mid k \notin S \}$$ 其中 $S$ 为有限整数集,$\mathbb{N}_0$ 表示非负整数集。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值