zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 74 (Rated for Div. 2) C. Standard Free2play

    链接:

    https://codeforces.com/contest/1238/problem/C

    题意:

    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 h, and there is a moving platform on each height x from 1 to h.

    Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms on heights p1,p2,…,pn. The platform on height h is moved out (and the character is initially standing there).

    If you character is standing on some moved out platform on height x, then he can pull a special lever, which switches the state of two platforms: on height x and x−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 2. In other words falling from the platform x to platform x−2 is okay, but falling from x to x−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 h, 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 0 ground level?

    思路:

    考虑相连的几个位置,判断是否可以从x落到x-2, 否则就使用宝石

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 2e5 + 10;
    
    int n, m;
    int a[MAXN];
    
    int main()
    {
            int t;
            cin >> t;
            while (t--)
            {
                    cin >> n >> m;
                    for (int i = 1; i <= m; i++)
                            cin >> a[i];
                    if (a[m] != 0)
                            a[++m] = 0;
                    int cnt = 0, p = a[2]+1;
                    for (int i = 2; i <  m;)
                    {
                            p = a[i]+1;
                            if (a[i + 1] == p - 2)
                            {
                                    p = a[i + 1];
                                    i += 2;
                                    continue;
                            }
                            else
                            {
                                    cnt++;
                                    p = a[i + 1] + 1;
                                    i++;
                                    continue;
                            }
                    }
                    cout << cnt << endl;
            }
    
            return 0;
    }
    
  • 相关阅读:
    js网页滚动条滚动事件实例分析
    一个简单的登陆注册的页面
    几个例子弄懂JS 的setInterval的运行方式
    IIS线程池与ASP.NET线程池
    [翻译]了解ASP.NET底层架构(八)
    IIS提示Server Application Unavailable
    C/C++, Java和C#的编译过程解析
    C#学习系列-.NET体系结构
    C#技术漫谈之垃圾回收机制(GC)
    ASP.NET应用程序与页面生命周期
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11685939.html
Copyright © 2011-2022 走看看