jiejiejiang2004

题解:2024牛客多校第三场 A

A Bridging the Gap 2

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 1048576K,其他语言2097152K
Special Judge, 64bit IO Format: %lld

题目描述

A group of \(n\) walkers arrives at a riverbank at night. They want to cross the river using a boat, which is initially on their side. The boat can hold at most \(R\) walkers at a time and requires at least \(L (1≤L<R)\) walkers to operate.

Rowing the boat is a tiring task. Each time the boat is used to transport a group of walkers to the other side of the river, all walkers on the boat must have stamina greater than \(0\) , and each walker's stamina decreases by \(1\) after the trip. Initially, the \(i\)-th walker \((1≤i≤n)\) has a stamina value of \(h_i\).

You need to determine if it is possible to transport all the walkers to the other side of the river using the boat.

夜晚,一组 \(n\) 个步行者到达河岸。他们想使用一艘船过河,船最初在他们这边。这艘船一次最多可以载 \(R\) 个步行者,并且至少需要 \(L\)\(1 \leq L < R\))个步行者来操作。

划船是一项累人的任务。每次使用船将一组步行者运送到河对岸时,船上的所有步行者的体力值都必须大于 \(0\),并且每次旅行后,每个步行者的体力值都会减少 \(1\)。最初,第 \(i\) 个步行者(\(1 \leq i \leq n\))的体力值为 \(h_i\)

你需要判断是否有可能使用这艘船将所有步行者运送到河对岸。

输入描述:

The first line of input contains three integers \(n,L,R (1≤L<R≤n≤5×10^5 )\), denoting the number of walkers, the minimum and the maximum number of walkers to use the boat at a time, respectively.

The second line of input contains \(n\) integers \(h_1,h_2,\dots,h_n(1 \le h_i \le 5 \times 10^5)\) , where \(h_i(1≤i≤n)\) denotes the stamina value of the \(i\)-th walker.

第一行输入包含三个整数 \(n,L,R(1≤L<R≤n≤5×10^5 )\),分别表示步行者的数量、每次使用船只的最少步行者数量和最多步行者数量。

第二行输入包含 \(n\) 整数 \(h_1,h_2,\dots,h_n(1 \le h_i \le 5 \times 10^5)\) ,其中 \(h_i(1≤i≤n)\) 表示第 \(i\) 个步行者的体力值。

输出描述:

If it is possible to transport all the walkers to the other side of the river using the boat, output Yes in the first line (without quotes). Otherwise, output No in the first line (without quotes). You can output each letter in any case (lowercase or uppercase). For example, the strings yEs, yes, Yes, and YES will all be considered as positive replies.

如果可以用船将所有步行者运送到河对岸,则在第一行输出 Yes(不带引号)。否则,在第一行输出 No(不带引号)。您可以以任何大小写(小写或大写)输出每个字母。例如,字符串 yEs, yes, YesYES 都将被视为肯定回答。

示例1

输入

4 1 2
1 2 5 10

输出

Yes

示例2

输入

5 1 2
1 1 1 1 5

输出

No

示例3

输入

5 1 3
1 1 1 1 5

输出

Yes

示例4

输入

5 2 3
1 1 1 1 5

输出

No

示例5

输入

9 1 9
1 1 1 1 1 1 1 1 1

输出

Yes

题解

by Kylin & W.Sherlock.Henry

小船过河
过去一次每人需要消耗 \(1\) 点体力
来回一次就是 \(2\)

先预处理一下,每个人减去最后一次过去的耐力
剩下的耐力可用于来回运输

计算出总共最多可以来回多少次
再计算出每人最多可以来回多少次(不得大于总共的值)
这样可以有效防止溢出

给上述值求和,和 总共的次数与每次最少的人数的乘积 作比较
大于等于 就是能过
小于 就是不能过

我的代码

#include <iostream>
#include <algorithm>
#define int long long

int n,l,r,t;
const int N = 1e7 +10;
int a[N];
int need,sum;

signed main() {
    std::cin >> n >> l >> r;
    for(int i = 0 ; i < n ; i ++) {
        std::cin >> a[i];
        a[i] --;
    }

    t = (n-r)/(r-l) + ((n-r)%(r-l) ? 1 : 0);
    need = t*l;

    for(int i = 0 ; i < n ; i ++) {
        sum += std::min(a[i]/2,t);
    }

    if(sum < need) std::cout << "NO";
    else std::cout << "YES";
    return 0;
}

posted on 2024-07-24 16:42  Jiejiejiang  阅读(10)  评论(0编辑  收藏  举报

导航