传送门:http://acm.jlu.edu.cn/joj/showproblem.php?pid=2513
一道简单题,因为地下的概率和不是1,所以将所有概率加一起,用以前的M除以这个数就行了。
代码:
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int n, m;
int Case = 0;
while (scanf("%d%d", &n, &m) != EOF)
{
if (Case++ != 0)
printf("\n");
double a[100], sum = 0, q;
for (int i = 0; i < n; ++i)
{
char c;
double x, y;
scanf("%lf%c%lf", &x, &c, &y);
a[i] = 1 / y;
sum += a[i];
}
q = m / sum;
for (int i = 0; i < n; ++i)
{
if (i == 0)
printf("%.0lf", q * a[i]);
else
printf(" %.0lf", q * a[i]);
}
printf("\n");
}
return 0;
}