复数模板
点击查看代码
struct Complex{
double r,i;//real part , imaginary part
Complex(double r = 0,double i = 0) : r(r),i(i) {}//abc怎么你了?
Complex operator+(const Complex& other) const{
return Complex(r + other.r,i + other.i);
}
Complex operator-(const Complex& other) const{
return Complex(r - other.r,i - other.i);
}
Complex operator*(const Complex& other) const{
return Complex(r * other.r - i * other.i,r * other.i + i * other.r);
}
Complex operator/(const Complex& other) const{
double d = other.r * other.r + other.i * other.i;//denominator
return Complex((r * other.r - i * (-other.i)) / d,(r * (-other.i) + i * other.r) / d);
}
};
毫秒级?重置种子模板
点击查看代码
void Srand(){
clockid_t clk = 0;
struct timespec p = {0, 0};
clock_gettime(clk, &p);
srand((unsigned)p.tv_nsec);
return;
}