CF1238C.Standard Free2play

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height hh, and there is a moving platform on each height xx from 11 to hh.

Each platform is either hidden inside the cliff or moved out. At first, there are nn moved out platforms on heights p1,p2,…,pnp_1, p_2, \dots, p_n. The platform on height hh is moved out (and the character is initially standing there).

If you character is standing on some moved out platform on height xx, then he can pull a special lever, which switches the state of two platforms: on height xx and x−1x - 1. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.

Your character is quite fragile, so it can safely fall from the height no more than 22. In other words falling from the platform xx to platform x−2x - 2 is okay, but falling from xx to x−3x - 3 (or lower) is certain death.

Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height hh, which is unaffected by the crystals). After being used, the crystal disappears.

What is the minimum number of magic crystal you need to buy to safely land on the 00 ground level?

你正在玩一款游戏,你的角色需要克服各种障碍。当前的问题是从悬崖上下来。悬崖的高度为 hh,在从 11 到 hh 的每一高度 xx 处都设有一个移动平台。

每个平台要么隐藏在悬崖内部,要么伸出悬崖外。初始时,共有 nn 个伸出的平台,其高度分别为 p1,p2,…,pnp_1, p_2, \dots, p_n。高度为 hh 的平台是伸出的(你的角色初始就站在该平台上)。

若你的角色正站在某个伸出的平台(高度为 xx)上,则他可以拉动一个特殊操纵杆,从而切换两个平台的状态:高度为 xx 和 x−1x - 1 的平台。换言之,你当前所站的平台将缩回悬崖内,而下方一单位高度(即高度为 x−1x - 1)的平台状态将发生翻转:若它原本是伸出的,则变为隐藏;若原本是隐藏的,则变为伸出。在后一种情形下,你将安全地降落到该平台上。注意,这是你从一个平台移动到另一个平台的唯一方式。

你的角色非常脆弱,因此最多只能安全下落 22 个单位高度。也就是说,从高度 xx 的平台下落到高度 x−2x - 2 的平台是安全的,但从 xx 下落到 x−3x - 3(或更低)则必然导致死亡。

有时,无法仅靠操纵杆操作安全抵达地面(高度 00),但你总能购买(通过捐赠货币)若干魔法水晶。每颗魔法水晶可用于改变任意一个平台的状态(但高度为 hh 的平台不受水晶影响)。水晶使用后即消失。

请问:为安全抵达地面(高度 00),你最少需要购买多少颗魔法水晶?

输入格式

The first line contains one integer qq (1≤q≤1001 \le q \le 100) — the number of queries. Each query contains two lines and is independent of all other queries.

The first line of each query contains two integers hh and nn (1≤h≤1091 \le h \le 10^9, 1≤n≤min⁡(h,2⋅105)1 \le n \le \min(h, 2 \cdot 10^5)) — the height of the cliff and the number of moved out platforms.

The second line contains nn integers p1,p2,…,pnp_1, p_2, \dots, p_n (h=p1>p2>⋯>pn≥1h = p_1 \gt p_2 \gt \dots \gt p_n \ge 1) — the corresponding moved out platforms in the descending order of their heights.

The sum of nn over all queries does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 qq(1≤q≤1001 \le q \le 100),表示查询次数。每次查询包含两行,且各次查询相互独立。

每次查询的第一行包含两个整数 hh 和 nn(1≤h≤1091 \le h \le 10^9,1≤n≤min⁡(h,2⋅105)1 \le n \le \min(h, 2 \cdot 10^5)),分别表示悬崖的高度以及被移除的平台数量。

每次查询的第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \dots, p_n(满足 h=p1>p2>⋯>pn≥1h = p_1 \gt p_2 \gt \dots \gt p_n \ge 1),表示按高度从高到低排列的被移除平台的位置。

所有查询中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each query print one integer — the minimum number of magic crystals you have to spend to safely come down on the ground level (with height 00).

对于每个查询,输出一个整数——安全降落到地面(高度为 00)所需花费的最少魔法水晶数量。

输入输出样例

  • 输入#1

    4
    3 2
    3 1
    8 6
    8 7 6 5 3 2
    9 6
    9 8 5 4 3 1
    1 1
    1

    输出#1

    0
    1
    2
    0

输入解题思路,AI测评打分。不知道怎么写?

首页