#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> bottles(n);
    for (int i = 0; i < n; i++) {
        cin >> bottles[i];
    }

    int left = 0;
    int right = n - 1;
    while (left <= right && bottles[left] == 0) {
        left++;
    }
    while (left <= right && bottles[right] == 0) {
        right--;
    }

    int count = 0;
    while (left <= right) {
        int temp = 0;
        while (left <= right && bottles[left] == 1) {
            temp++;
            left++;
        }
        if (temp > 0) {
            count++;
        }
        while (left <= right && bottles[left] == 0) {
            left++;
        }
    }

    cout << count << endl;

    return 0;
}
``
# drink## 题目背景!httpscdnluogucomcnuploadimage_hosting8u8szw7zpng## 题目描述你面前有 $n$ 个瓶子从左到右依次编号为 $1 sim n$瓶子可能是空的也可能装着水。你可以选择一对 $lrl le r$然后把 $lsim r$ 号瓶子中的所有水全部喝完。你想一口气把桌上剩的水全喝完请问你最少要拿起几个瓶子?你有可能一个瓶子都不需要拿起

原文地址: https://www.cveoy.top/t/topic/iBwP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录