一些可能用得上的板子

复数模板

点击查看代码
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);
  }
};

毫秒级?重置种子模板

linux
void Srand(){
  clockid_t clk = 0;
  struct timespec p = {0, 0};
  clock_gettime(clk, &p);
  srand((unsigned)p.tv_nsec);
  return;
}
windows
#include <Windows.h>
void Srand(){
  SYSTEMTIME ct;
  GetLocalTime(&ct);
  srand(ct.wYear + ct.wMonth + ct.wDayOfWeek + ct.wDay + ct.wHour + ct.wMinute + ct.wSecond + ct.wMilliseconds);
  return;
}
posted @ 2023-11-06 15:27  静观默察  阅读(18)  评论(0)    收藏  举报