UVA - 10056 What is the Probability

/*
  这题其实并不难,可以说,算是比较简单的概率题了...涉及到一点等比级数求和,但这也是高数里面学过公式的,总之,没做出来有些不应该
  
  注意下:浮点数是有误差的,所以p为0时,要单独特判,并且特判时也要注意小数点位数,思考方面不太难,但如果不注重细节,很容易WA
*/

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double IS = 1e-6;
int main()
{
	int s, n, i;
	double p;
	cin >> s;
	while (s--)
	{
		cin >> n >> p >> i;
		if (p < IS) cout << "0.0000" << endl;
		else cout << fixed << setprecision(4) << p * pow(1 - p, i - 1) / ( 1 - pow(1 - p, n) ) << endl;
	}
	return 0;
}

posted @ 2017-08-31 15:34  mofushaohua  阅读(173)  评论(0)    收藏  举报