其他分享
首页 > 其他分享> > cf C. Standard Free2play模拟贪心

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;
}

 

标签:Free2play,台阶,int,scanf,cf,Standard,++,ans,include
来源: https://blog.csdn.net/ClonH/article/details/102776696