The 2021 CCPC Weihai Onsite E CHASE!
概率 \(dp\) + 双指针
占个坑,说明补了这题,题解没时间写了,先咕咕了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x)
{
return (x > eps) - (x < -eps);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q, k;
cin >> n >> k >> q;
vector<ll>a(n + 1), sum(n + 1, 0);
for(int i=1; i<=n; i++) cin >> a[i];
vector<ll> b = a;
sort(a.begin() + 1, a.end());
for(int i=1; i<=n; i++) sum[i] = sum[i - 1] + a[i];
vector<double>E(k + 1);
for(int i=1; i<=n; i++) E[0] += (n - 1) * a[i];
E[0] /= 1ll * n * (n - 1) / 2;
for(int i=1; i<=k; i++)
{
double p = E[0], tot = 0;
int l = 1, r = n;
ll cnt = 0;
while(l <= n)
{
while(r >= l && a[r] + a[l] >= E[i - 1]) r--;
if(l > r) break;
ll len = r - l;
p -= (len * a[l] + sum[r] - sum[l]) / (1.0 * n * (n - 1)) * 2;
tot += len;
l++;
}
p += E[i - 1] / (1ll * n * (n - 1)) * 2 * tot;
E[i] = p;
}
cout << fixed << setprecision(20) << E[k] << "\n";
while(q--)
{
ll x, y, c;
cin >> x >> y >> c;
if(c == 0) cout << "accept\n";
else
{
int dif = dcmp(b[x] + b[y] - E[c - 1]);
if(dif == 0) cout << "both\n";
else if(dif == 1) cout << "accept\n";
else cout << "reselect\n";
}
}
return 0;
}