Bridging the Gap 2

题目


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 hi​.

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

思路

       题目中所说最少L人,最多R人,其实可以看做在一趟中可以将R-L人送到对岸,那么根据总人数可以推测得到趟数,每趟需要L人去划船送R-L人过去,那么其实需要的打工次数应该是趟数*L,对于每个人来说减去自己真正过去(到达对岸不过来)的所需的一点体力,剩下的体力值除以2,就是他可以打工的次数,但是对于团队而言,他打工的上限是趟数,计算整个团队可以打工的数量与需要的打工次数比较即可。

代码

#include <bits/stdc++.h>
using namespace std;
long long int a[500005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);  
    cout.tie(0);
    int n, l, r;
    long long int sum = 0, cnt = 0;
    cin >> n >> l >> r;
    if((n - r) % (r - l) == 0) {
        sum = (n - r) / (r - l);
    }
    else{
        sum = (n - r) / (r - l) + 1;
    }
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt += min((a[i] - 1) / 2, sum);
    }
    if(cnt >= sum * l)  cout << "Yes\n";
    else  cout << "No\n";
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值