题解:P15017 [UOI 2020 II Stage] 大炮

· · 题解

P15017 [UOI 2020 II Stage] 大炮 题解

思路

通过观察示意图可知:如果当前哥萨克的高度不小于下一段路钟乳石的高度他就会撞到钟乳石上下落。

AC 代码

#include <bits/stdc++.h> 
using namespace std; 
int main () {
    ios::sync_with_stdio (0); 
    cin.tie (0); 
    cout.tie (0); 
    int n; 
    cin >> n; 
    int a [n + 2]; 
    a [n + 1] = 0; 
    for (int i = 1; i <= n; i ++) {
        cin >> a [i]; 
    }
    int s = 0;
    int ans = 0; 
    for (int i = 1; i <= n; i ++) {
        s ++; 
        if (s >= a [i + 1]) {
            s = 1; 
            ans ++; 
        }
    }
    cout << ans; 
    return 0; 
}

感谢观看!