QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620715#2440. Valentine's Daymemset0AC ✓91ms3940kbC++23910b2024-10-07 20:43:302024-10-07 20:43:30

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 20:43:30]
  • 评测
  • 测评结果:AC
  • 用时:91ms
  • 内存:3940kb
  • [2024-10-07 20:43:30]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define endl '\n'
#define log(...) (void(0))
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;

const int N = 1e4 + 9;
int T, n;
double p[N];

int main() {
#ifdef memset0
  freopen("C.in", "r", stdin);
#endif
  cin.tie(0)->sync_with_stdio(0);
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> p[i];
    }
    sort(p + 1, p + n + 1);
    reverse(p + 1, p + n + 1);
    double ans = p[1], pre = 1 - p[1];
    for (int i = 2; i <= n; i++) {
      double cur = ans * (1 - p[i]) + pre * p[i];
      if (cur > ans) {
        ans = cur;
        pre *= 1 - p[i];
      } else {
        break;
      }
    }
    cout << fixed << setprecision(12) << ans << endl;
  }
}

详细

Test #1:

score: 100
Accepted
time: 91ms
memory: 3940kb

input:

100
10
0.020874 0.180969 0.015588 0.043033 0.181293 0.033025 0.163341 0.104341 0.065442 0.129546
10
0.019357 0.210598 0.045487 0.051145 0.014579 0.135566 0.004401 0.008004 0.106695 0.056974
10
0.062679 0.216144 0.010137 0.031823 0.233062 0.042464 0.099544 0.140483 0.201337 0.045349
100
0.116404 0.19...

output:

0.398190071489
0.373683886459
0.410885362758
0.421374044378
0.419872971016
0.421062257019
0.420796858020
0.419890897576
0.419860393202
0.000099990100
0.000000000000
0.003341000000
0.003336000000
0.001427003306
0.003169000000
0.029231252961
0.061862431346
0.022757483568
0.015698496871
0.035934479901
...

result:

ok 100 numbers