11.1—分治法—Pow(x,n)
来源:互联网 发布:linux下的下载工具 编辑:程序博客网 时间:2024/05/28 05:18
描述
Implement pow(x, n).
Implement pow(x, n).
#include<iostream>#include<cmath>using namespace std;#define eps 0.0000001bool flag = true;double MyPow(double x, int n){if (n == 0){if (abs(x) >= eps)return 1;else{cerr << "0的0次方无意义!" << endl;flag = false;return -1;}}else if (n > 0){if (abs(x) < eps){return 0;}else{if (n % 2 == 0){double temp=MyPow(x, n / 2);return temp*temp;}else{double temp = MyPow(x, (n-1) / 2);return x*temp*temp;}}}else{if (abs(x) >= eps)return 1.0 / MyPow(x, -n);else{cerr << "0的" << n << "次方无意义!" << endl;flag = false;return -1;}}}int main(){int n = 5;double x = 4;double res = MyPow(x, n);if (flag)cout << res << endl;}
阅读全文
0 0
- 11.1—分治法—Pow(x,n)
- [leetcode] 【分治法】 50. Pow(x, n)
- LeetCode Pow(x,n)(分治法)
- 分治法实现pow(x,n)函数的功能
- LeetCode 之 Pow(x, n)(分治法)
- [算法作业][LeetCode] 50. Pow(x, n) -- 分治法
- [leetCode] Pow(x,n)(分治)
- 50. Pow(x, n)(分治)
- 11.1 Pow(x, n)
- LeetCode —— Pow(x, n)
- LeetCode——Pow(x, n)
- leetcode 050 —— Pow(x, n)
- LeetCode50——Pow(x,n)
- Algorithms—50.Pow(x, n)
- 【leetcode 分治法】Pow(x, n)与Sqrt(x)函数的实现
- Pow(x, n) / Super Pow
- leetcode——50——Pow(x, n)
- Leetcode刷题记——50. Pow(x, n)
- 8.6—暴力枚举法—Letter Combinations of a Phone Number
- Android Camera结合Zxing优化扫码
- 算法编程题-判断一颗树中是否有与另一棵树拓扑结构完全相同的子树
- 使用Aspose.Cells实现后台输出Excel报表(C#)
- 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环境变量的配置问题