Lucky Coins
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1654 Accepted Submission(s): 601
Problem Description
Input
Output
Sample Input
Sample Output
Source
Recommend
Solution
參考 https://blog.csdn.net/vici__/article/details/82935968
die[i][j]: 第i種硬幣在第j步之前(包括第j步)全部被淘汰的概率
live[i][j]: 第i種硬幣在第j步之前(包括第j步)倖存的概率
對於第i種硬幣,枚舉它勝出前經過的回合數。(當第j回合結束時除i以外的所有硬幣都淘汰,當第j+1回合時i淘汰)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
double die[10][100], live[10][100];
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(false);
int t, n, m;
double p, ans, prod;
cin >> t;
while (t--)
{
cin >> n;
memset(die, 0, sizeof(die));
memset(live, 0, sizeof(live));
for (int i = 1; i <= n; i++)
{
cin >> m >> p;
for (int j = 1; j < 100; j++)
{
die[i][j] = pow(1.0 - pow(p, j), m);
live[i][j] = 1.0 - die[i][j];
}
}
if (n == 1)
{
printf("%.6f\n", 1.0);
continue;
}
for (int i = 1; i <= n; i++)
{
ans = 0.0;
for (int j = 1; j < 100; j++)
{
prod = 1.0;
for (int k = 1; k <= n; k++) if (k != i) prod *= die[k][j];
ans += (live[i][j] - live[i][j + 1]) * prod;
}
printf("%.6f%s", ans, i == n ? "\n" : " ");
}
}
return 0;
}