Saturday, June 13, 2015

UVa 10056 - What is the Probability ?

// UVa 10056 - What is the Probability ?
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
	int c, n, m;
	double p;
	cin >> c;
	for (; c; c--) {
		cin >> n >> p >> m;
		int i = 1;
		double common_fact = p * pow(1 - p, m - 1);
		double previous = common_fact;
		double current = previous + common_fact * pow(1 - p, n);
		while (current - previous > 0.0000001) {
			i++;
			previous = current;
			current = previous + common_fact * pow(1 - p, i * n);

		}
		printf("%.4f\n", current);
	}
	return 0;
}

No comments:

Post a Comment