cf C. Standard Free2play模拟贪心

题目链接:http://codeforces.com/contest/1238/problem/C

题意:在一个高度为h的山上每个高度都有台阶, 其中有n个台阶显示出来,其他都是闭上的,只有显示的能跳,但每跳到一个台阶下一个高度的台阶状态就会变换(注意不是下一个显示的台阶,而是下一个高度x+1)闭上的打开,打开的闭上,如果跳到比原来大于2个距离就会死,每次魔法可以改变某个台阶的状态,问不死跳到底最少需要多少次魔法。

ac代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <set>
#include <iterator>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int mx = 2e5+10;
const ll mod = 1e9+7;
int f[mx];
int main()
{
    int n, m, h;
    for (scanf("%d",&m); m--;) {
        scanf("%d%d", &h, &n);
        for (int i = 0; i < n; ++i) scanf("%d", &f[i]);
        f[n] = 0;
        int ans = 0;
        for (int i = 1; i < n; ++i) {
            if (f[i]-f[i+1] > 1) ans++;
            else i++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值