题目
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;
}