一些可能用得上的板子

发布时间 2023-10-31 08:38:45作者: 静观默察

复数模板

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;
}