11.2—分治法—Sqrt(x)
来源:互联网 发布:社交网络剧情 编辑:程序博客网 时间:2024/05/19 20:00
描述
Implement int sqrt(int x).
Compute and return the square root of x.
Implement int sqrt(int x).
Compute and return the square root of x.
#include<iostream>#include<vector>#include<cmath>#define eps 0.000001using namespace std;bool flag = true;vector<double> Sqrt(double a){if (a < -eps){cerr << "输入错误!" << endl;flag = false;return vector < double > {-1, -1};}else if (abs(a) <= eps)return vector < double > {0, 0};else{double x0 = 5;double y0 = x0*x0 - a;while (abs(y0) > eps){double x = x0 - y0 / (2 * x0);double y = x*x - a;//===x0 = x;y0 = y;}return vector < double > {x0, -x0};}}int main(){double a =9;vector<double> res = Sqrt(a);if (flag)cout << res[0] << " " << res[1] << endl;}
阅读全文
0 0
- 11.2—分治法—Sqrt(x)
- [leetcode] 【分治法】 69. Sqrt(x)
- 69. Sqrt(x)(分治)
- LeetCode —— Sqrt(x)
- LeetCode——Sqrt(x)
- LeetCode——Sqrt(x)
- LeetCode69——Sqrt(x)
- 【leetcode 分治法】Pow(x, n)与Sqrt(x)函数的实现
- 11.2 Sqrt(x)
- leetcode 069 —— Sqrt(x)
- Hold住Leetcode—— Sqrt(x)
- Leetcode——69. Sqrt(x)
- 算法系列——Sqrt(x)
- LeetCode 之 Sqrt(x) — C 实现
- 11.1—分治法—Pow(x,n)
- leetcode——69——Sqrt(x)
- 数据结构与算法[LeetCode]——sqrt(x)
- Leetcode代码学习周记——Sqrt(x)
- java反射的field.get(null)
- 11.1—分治法—Pow(x,n)
- Ubuntu16.04如何将普通用户提升至root权限
- caffe随记(四) --- mnist示例超详细讲解
- Mac 使用 80 端口
- 11.2—分治法—Sqrt(x)
- 12.1—贪心法—Jump Game
- 信息系统设计师的出路有哪些?
- css 小技巧
- 在linux中安装jdk,以及linux下java环境变量的配置问题
- 12.2—贪心法—Jump Game II
- iOS中的@property的属性
- 游戏room8 第六关的答案
- 12.3—贪心法—Best Time to Buy and Sell Sto