2079.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 39 行

CPP
39
字号
/*  This Code is Submitted by wywcgs for Problem 2079 on 2005-10-15 at 09:12:09 */ 
#include <stdio.h>
#include <math.h>

double t;

double except(int, double);

int main()
{
	int n;

	while(scanf("%d %lf", &n, &t) == 2) {
		if(n == 0 && fabs(t) < 1e-3) {
			return 0;
		} else {
			printf("%.3lf\n", except(n, 1));
		}
	}
	
	return 0;
}

double except(int n, double a)
{
	double p, total;
	if(n == 0) {
		return a;
	} else {
		total = except(n-1, 2*a);
		p = a / total;
		if(t - p < 1e-3) {
			return (a*(p-t)+total*(1-p*p)/2)/(1-t);
		} else {
			return total*(1-t*t)/(2*(1-t));
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?