Standard Free2play
直接模拟就行:
有两个挡板分别在100,50的位置,那么就可以一步步的跳到51的位置
现在来到了51的位置,50有个挡板,如果49的位置有挡板,那么可以直接跳到49
如果下一个挡板在45的位置,从51跳下会嗝屁,氪金大法,在50的位置开个挂,跳到50
一步步的走就行了
复杂度O(n)
Code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a));
#define lowbit(x) (x & -x)
#define lrt nl, mid, rt << 1
#define rrt mid + 1, nr, rt << 1 | 1
template <typename T>
inline void read(T& t) {
t = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
t = t * 10 + ch - '0';
ch = getchar();
}
t *= f;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll Inf = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x7f7f7f7f;
const double eps = 1e-5;
const double Pi = acos(-1);
const int maxn = 2e5 + 5;
int an[maxn];
int main(void) {
int T;
read(T);
while (T--) {
int n, m;
read(n), read(m);
for (int i = 1; i <= m; i++)
read(an[i]);
an[m + 1] = 0;
an[m + 2] = -1;
int pos = n, ans = 0;
for (int i = 2; i <= m + 1; i++) {
if (an[i] >= pos)
continue;
pos = an[i] + 1;
if (an[i + 1] == an[i] - 1)
pos = an[i + 1];
else {
ans++;
pos = an[i];
}
}
printf("%d\n", ans);
}
return 0;
}