解题思路
预处理与初始检查:
首先检查第 天的总 是否已达到目标值 。
计算每首曲子达到 准确率所需的最大天数,确定二分查找的上界。
二分查找策略:
在可能的天数范围内进行二分查找。 对于每个中间天数 ,计算该天的总 并与目标值比较。
单曲 计算:
根据给定的公式计算每首曲子在第 天的单曲 。 使用优先队列维护最大的 个单曲 值。 总 计算:
结合初始的 个单曲 和第 天的单曲 ,找出最大的 个值。 找出准确率为 的曲子中的最大单曲 。 计算这 5 个值的平均值并保留两位小数。
#include<bits/stdc++.h>
using namespace std;
double retain2(double x) {
x *= 100;
int y = static_cast<int>(x);
return y / 100.0;
}
struct Song {
double a, b, c;
};
double compute_total_rks(int k, const vector<Song>& songs, const vector<double>& d) {
priority_queue<double, vector<double>, greater<double>> top4;
for (int i = 0; i < 4; ++i) {
top4.push(d[i]);
}
double max_100_rks = d[4];
for (const auto& song : songs) {
double a = song.a;
double b = song.b;
double c = song.c;
double acc = a + (k - 1) * b;
acc = min(acc, 100.0);
double rks_i = 0.0;
if (acc >= 70.0) {
double temp = (acc - 55.0) / 45.0;
temp = retain2(temp);
double temp_sq = temp * temp;
temp_sq = retain2(temp_sq);
rks_i = temp_sq * c;
rks_i = retain2(rks_i);
}
if (rks_i > top4.top()) {
top4.pop();
top4.push(rks_i);
}
if (acc >= 100.0 - 1e-9) {
if (rks_i > max_100_rks) {
max_100_rks = rks_i;
}
}
}
double sum_top4 = 0.0;
vector<double> temp;
while (!top4.empty()) {
temp.push_back(top4.top());
top4.pop();
}
for (double val : temp) {
sum_top4 += val;
}
double total = (sum_top4 + max_100_rks) / 5.0;
total = retain2(total);
return total;
}
int main() {
int n;
double m;
cin >> n >> m;
vector<Song> songs(n);
for (int i = 0; i < n; ++i) {
cin >> songs[i].a >> songs[i].b >> songs[i].c;
}
vector<double> d(5);
for (int i = 0; i < 5; ++i) {
cin >> d[i];
}
double total_0 = (d[0] + d[1] + d[2] + d[3] + d[4]) / 5.0;
total_0 = retain2(total_0);
if (total_0 >= m) {
cout << 0 << endl;
return 0;
}
int max_k = 0;
for (const auto& song : songs) {
double a = song.a;
double b = song.b;
if (a >= 100.0) {
max_k = max(max_k, 1);
continue;
}
double delta = 100.0 - a;
double t = delta / b;
int k_i = static_cast<int>(ceil(t)) + 1;
max_k = max(max_k, k_i);
}
int left = 1, right = max_k;
int ans = -1;
while (left <= right) {
int mid = (left + right) / 2;
double current_total = compute_total_rks(mid, songs, d);
if (current_total >= m) {
ans = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
if (ans != -1) {
cout << ans << endl;
} else {
cout << -1 << endl;
}
return 0;
}