最近发现一款文法分析神器,看完官网(http://goldparser.org/)的介绍后感觉很犀利的样子,于是就拿来测试了一番,写了一个数学表达式分析的小程序,支持的数学运算符如下所示:常规运算:+ - * / ^ sqrt sqrt2(a,b) pow2(a) pow(a,b)三角函数:si.....
分类:
其他好文 时间:
2014-08-14 20:24:49
阅读次数:
372
原题:
Implement pow(x, n).
思路:递归计算pow。
class Solution {
public:
double pow(double x, int n) {
long long int mid = n/2;
int d = n%2;
if(n==0) return 1;
if(n==1) return ...
分类:
其他好文 时间:
2014-08-14 16:54:38
阅读次数:
229
使用时注意类型,可见两者皆不可以用int1.pow函数声明: double pow (double base , double exponent); float pow (float base , float exponent);long double pow (...
分类:
其他好文 时间:
2014-08-13 17:59:26
阅读次数:
184
int pow_mod(int a,int b,int n)
{
int ans ;
if(b == 0)
return 1 ;
ans = pow_mod(a,b/2,n);
ans = ans * ans % n ;
if( b%2 )
ans = ans*a % n ;
return ans ;
}...
分类:
其他好文 时间:
2014-08-10 13:04:30
阅读次数:
196
画一个心形有非常多公式能够使用,以下这个公式我觉得最完美了:float x = R * 16 * pow(sin(theta), 3);float y = R * (13 * cos(theta) - 5*cos(2*theta) - 2*cos(3*theta) - cos(4*theta));画...
分类:
其他好文 时间:
2014-08-08 17:43:06
阅读次数:
291
Problem Description:
Implement pow(x, n).
分析:题目意思很简单,要求计算x的n次幂,其中x给的是double类型,n需要考虑负数的情况,利用二分的思想每次将n减半,递归计算可以得到最终结果,其中一些细节需要注意,具体的实现代码如下:
class Solution {
public:
bool isequal(double a,doubl...
分类:
其他好文 时间:
2014-08-07 19:17:00
阅读次数:
179
求2的32次方
普通程序员
Java code ?
1System.out.println(Math.pow(2, 32));
文艺程序员
Java code ?
1System.out.println(1L
2B程序员
Java code ?
1System.out.println(2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*...
分类:
其他好文 时间:
2014-08-06 19:26:42
阅读次数:
261
sqrt(pow((X1-X2),2)+pow((Y1-Y2),2)+pow((Z1-Z2),2))/10floatX=pow ($BB.pos.x- $AA.pos.x) 2floatY=pow ($BB.pos.y- $AA.pos.y) 2floatZ=pow ($BB.pos.z- $AA....
分类:
其他好文 时间:
2014-08-06 18:49:41
阅读次数:
171
//(2^n-1)%mod
//费马小定理:a^n ≡ a^(n%(m-1)) * a^(m-1)≡ a^(n%(m-1)) (mod m)
# include
# include
# include
# define mod 1000000007
using namespace std;
__int64 pow(__int64 n)
{
__int64 p=1,q=2;
w...
分类:
其他好文 时间:
2014-08-05 22:40:30
阅读次数:
242
Implement pow(x, n).
思路:快速幂运算,需要考虑指数为负数,同时底数为0的情况,这种属于异常数据,代码里没有体现。
class Solution {
public:
double pow_abs(double x, unsigned int n)
{
if (n == 0)
{
return 1;...
分类:
其他好文 时间:
2014-08-04 21:32:48
阅读次数:
314