题解: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 n 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 R R walkers at a time and requires at least L ( 1 ≤ L < R ) L (1≤L<R) L(1L<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 0 0 , and each walker’s stamina decreases by 1 1 1 after the trip. Initially, the i i i-th walker ( 1 ≤ i ≤ n ) (1≤i≤n) (1in) has a stamina value of h i h_i hi.

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

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

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

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

输入描述:

The first line of input contains three integers n , L , R ( 1 ≤ L < R ≤ n ≤ 5 × 1 0 5 ) n,L,R (1≤L<R≤n≤5×10^5 ) n,L,R(1L<Rn5×105), 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 n n integers h 1 , h 2 , … , h n ( 1 ≤ h i ≤ 5 × 1 0 5 ) h_1,h_2,\dots,h_n(1 \le h_i \le 5 \times 10^5) h1,h2,,hn(1hi5×105) , where h i ( 1 ≤ i ≤ n ) h_i(1≤i≤n) hi(1in) denotes the stamina value of the i i i-th walker.

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

第二行输入包含 n n n 整数 h 1 , h 2 , … , h n ( 1 ≤ h i ≤ 5 × 1 0 5 ) h_1,h_2,\dots,h_n(1 \le h_i \le 5 \times 10^5) h1,h2,,hn(1hi5×105) ,其中 h i ( 1 ≤ i ≤ n ) h_i(1≤i≤n) hi(1in) 表示第 i i 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 1 1 点体力
来回一次就是 2 2 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;
}

转载自博客https://www.cnblogs.com/jiejiejiang2004/p/18321150
博主已同意,我就是博主

  • 9
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值