[Codeforces 1238C] Standard Free2play(贪心)

语文题,不,是英语题,发几个公告理解题意

Problem C. Standard Free2play
*****
Pulling a lever is the only way to get to the lower platform. Explanation of sample 3: We can, for example, move out platform 7 and platform 2. At first, the character is on platform 9, he pulls the lever and falls to 7. Then he pulls the lever and falls to 6; Then he pulls the lever and falls to 4; Then he pulls the lever and falls to 2; Then he pulls the lever and falls to 0 - ground.

Problem C. Standard Free2play
*****
As written in the statement, pulling a lever is the only way to get down. 

Problem C. Standard Free2play
*****
In the sample case 3, you CANNOT use the crystal on platfrom 7, then move 9 -> 7, and then move 7 -> 5, because when you pull the lever on platform 7, the platform 6 will move out.

贪心往下走

用魔法时可选h-1,h-2那么选h-1,后面是空的,从h-1出去h-2就升起来了,都一样

#include <iostream>
#include <queue>
#include <cstring>
#include <cmath>
#include <algorithm>
 
using namespace std;

int p[200010];  
  
int main() {
	int q,n,h;
	cin >> q;
	while(q--) {
	  cin >> h >> n;
	  for (int i = 1; i <= n; i++) scanf("%d",&p[i]);
	  int ans = 0;
	  p[++n] = 0;
	  for (int i = 2; i <= n; i++) {
	  	 //if (h == p[i]) continue;
	     if (h > p[i]+1) h = p[i]+1;
		 if (h-p[i+1] > 2) {
		 	ans++;
		 	h = h-1;
		 } else h = p[++i];	
	  }
	  cout << ans << "\n";
    }
    return 0;
}

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,…,pnp1,p2,…,pn. 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?

Input

The first line contains one integer qq (1≤q≤1001≤q≤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≤h≤109, 1≤n≤min(h,2⋅105)1≤n≤min(h,2⋅105)) — the height of the cliff and the number of moved out platforms.

The second line contains nn integers p1,p2,…,pnp1,p2,…,pn (h=p1>p2>⋯>pn≥1h=p1>p2>⋯>pn≥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⋅105.

Output

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).

Example

input

Copy

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

output

Copy

0
1
2
0

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值