题解:AT_abc392_d [ABC392D] Doubles
FlowerAccepted · · 题解
解题思路
记最大点数为
注意到一个 dice 可能有若干个相同的面,所以可以开一个大小
每次取 dice
注意精度喵~要先除再乘开 long double 呦!要 printf("%.15f")呦!不然 dice 们就会给你一个
代码呈现
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring> // aple clang 专属
using namespace std;
int a[105], qwq[105][100005]; // 开大防越界
int main() {
int n, x, maxx = 0; // MAXA
long double maxpos = 0, pos; // 答案、目前概率
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
for (int j = 1; j <= a[i]; j ++) {
cin >> x;
qwq[i][x] ++; // 桶计数
maxx = max(maxx, x); // 最大点数
}
}
for (int i = 1; i < n; i ++) {
for (int j = i + 1; j <= n; j ++) {
pos = 0;
for (int k = 1; k <= maxx; k ++) {
pos += ((long double)qwq[i][k] / a[i]) * ((long double)qwq[j][k] / a[j]); // 十天 AT 一场空,不开 ld 先乘见祖宗!
}
maxpos = max(maxpos, pos); // 取最大值
}
}
printf("%.15Lf", maxpos); // 正常输出只能 5 或 6 位
return 0;
}
复杂度分析
复杂度不小,是
后记 & 整活
好想要 U dice 啊!