[ARC075B] Widespread
题意:给(n)个人血量,然后一次攻击只能对一个人造成(a)伤害,对其他人造成(b)伤害,求最少次数打败全部敌人。
题解:二分我是没想到的,直接二分次数,然后(O(n))判断是否能全打败就可以了。
代码:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
const ll N = 1e5 + 99;
const ll Max = 1e9 + 99;
ll h[N];
ll first[N];
ll a, b;
ll n;
bool check(ll mid) {
ll cnta = mid;
for (int i = 1; i <= n; i++) {
if (h[i] - mid * b <= 0) {
continue;
} else {
ll d = h[i] - mid * b;
ll dd = a - b;
ll Cnt = d / dd + (d % dd == 0 ? 0 : 1);
cnta -= Cnt;
}
}
if (cnta < 0) {
return 1;
} return 0;
}
void solve() {
cin >> n;
cin >> a >> b;
for (ll i = 1; i <= n; i++) {
cin >> h[i];
}
ll cnt = 0;
sort(h + 1, h + 1 + n);
ll l = 0, r = Max;
while ( l < r) {
ll mid = (l + r) >> 1;
if (check(mid)) {
l = mid + 1;
//cout << "?0;";
} else {
r = mid;
//cout << "))_
";
}
//cout << l << " " << r << endl;
}
cout << l << endl;
}
signed main() {
ll t = 1;
//cin >> t;
while (t--) {
solve();
}
}