C. Standard Free2play

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

 

写了各种特判不对,最后在数组后面加一个0 的高度AC了

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#define ll              long long
#define PII             pair<int, int>
#define rep(i,a,b)      for(int  i=a;i<=b;i++)
#define dec(i,a,b)      for(int  i=a;i>=b;i--)
using namespace std;
int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const double eps = 1e-6;
const int mod =1e9+7;
const int N = 100005;
//if(x<0 || x>=r || y<0 || y>=c)

inline ll read()
{
    ll x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}
ll gcd(ll m, ll n)
{
    return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
    return m * n / gcd(m, n);
}
ll qpow(ll m, ll k, ll mod)
{
    ll res = 1, t = m;
    while (k)
    {
        if (k & 1)
            res = res * t % mod;
        t = t * t % mod;
        k >>= 1;
    }
    return res;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        ll h, n;
        cin >> h >> n;
        n++;
        vector<int> a(n);
        for (int i = 0; i < n-1; i++)
        {
            a[i] = read();
        }
        a[n-1] = 0;
        int res = 0, pos = 0;
        for (int i = 0; i < n - 2; i++)
        {
            if (a[i] - a[i + 1] == 1)
            {
                if (a[i] - a[i + 2] > 2)
                    res++, a[i + 1] = a[i + 2] + 1;
                else
                    i++;
            }
            else
                a[i] = a[i + 1] + 1,i--;
            pos = i + 1;
        }
        cout << res << endl;
    }
    return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#define ll              long long
#define PII             pair<int, int>
#define rep(i,a,b)      for(int  i=a;i<=b;i++)
#define dec(i,a,b)      for(int  i=a;i>=b;i--)
using namespace std;
int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const double eps = 1e-6;
const int mod =1e9+7;
const int N = 100005;
//if(x<0 || x>=r || y<0 || y>=c)

inline ll read()
{
    ll x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}
ll gcd(ll m, ll n)
{
    return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
    return m * n / gcd(m, n);
}
ll qpow(ll m, ll k, ll mod)
{
    ll res = 1, t = m;
    while (k)
    {
        if (k & 1)
            res = res * t % mod;
        t = t * t % mod;
        k >>= 1;
    }
    return res;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        ll h, n;
        cin >> h >> n;
        n++;
        vector<int> a(n);
        for (int i = 0; i < n-1; i++)
        {
            a[i] = read();
        }
        a[n-1] = 0;
        int res = 0, pos = 0;
        for (int i = 0; i < n - 2; i++)
        {
            if (a[i] - a[i + 1] == 1)
            {
                if (a[i] - a[i + 2] > 2)
                    res++, a[i + 1] = a[i + 2] + 1;
                else
                    i++;
            }
            else
                a[i] = a[i + 1] + 1,i--;
            pos = i + 1;
        }
        cout << res << endl;
    }
    return 0;
}

 

上一篇:css样式导致table合并表格rowspan和colspan失败


下一篇:Activity 的启动模式记录