标签:http r bs tt return 方法 d ip 5
这题没多大技巧性,只是牛顿迭代法多用于数值计算,这里出现有些意外。
维基上有方法说明:http://zh.wikipedia.org/wiki/牛顿法
    int sqrt(int x) {
    	if (x == 0)
		return 0;
	double x0 = 1.0;
	while (1){
		double x1 = 0.5 * x0 + (x / (2 * x0));
		if (abs(x1 - x0) < 1e-6)
			break;
		x0 = x1;
	}
	return x0;
    }
标签:http r bs tt return 方法 d ip 5
原文地址:http://www.cnblogs.com/hustxujinkang/p/4002712.html