QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69570#2440. Valentine's Dayhe_ren_shi_lyp#AC ✓155ms3884kbC++23625b2022-12-28 18:33:302022-12-28 18:33:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-28 18:33:32]
  • 评测
  • 测评结果:AC
  • 用时:155ms
  • 内存:3884kb
  • [2022-12-28 18:33:30]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 50;

long double p[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T;
	cin >> T;
		cout << fixed << setprecision(20);
	while (T--) {
		int n;
		cin >> n;
		for (int i = 1; i <= n; ++i)
			cin >> p[i];
		sort(p + 1, p + n + 1, greater<long double>());
		long double p0 = 1, p1 = 0;
		for (int i = 1; i <= n; ++i) {
			long double q0 = p0 * (1 - p[i]);
			long double q1 = p0 * p[i] + p1 * (1 - p[i]);
			if (q1 > p1) {
				p0 = q0;
				p1 = q1;
			}
		}
		cout << p1 << '\n';
	}
}

详细

Test #1:

score: 100
Accepted
time: 155ms
memory: 3884kb

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.39819007148890732525
0.37368388645907640552
0.41088536275849987464
0.42137404437828100437
0.41987297101569753056
0.42106225701885684705
0.42079685802045167287
0.41989089757572841045
0.41986039320215500805
0.00009999010048508432
0.00000000000000000000
0.00334100000000000000
0.00333600000000000000
0...

result:

ok 100 numbers