博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

复数模版

写着玩的,以证明我这两天没颓废……= =

大约是本blog最低水平的一篇???

#include<cmath>
#include<cstdio>
#include<algorithm>
#define eps 1e-9
#define ld long double
using namespace std;

int a,b,c,d,e;
struct com{
    ld r,i;
    com(ld _r=0,ld _i=0):r(_r),i(_i){};
    void pr(){printf("%Lf %Lf\n",r,i);}
}s[4],w;
com operator + (com a,com b){return com(a.r+b.r,a.i+b.i);}
com operator - (com a,com b){return com(a.r-b.r,a.i-b.i);}
com operator * (com a,com b){return com(a.r*b.r-a.i*b.i,a.r*b.i+a.i*b.r);}
com operator / (com a,com b){ld c=b.r*b.r+b.i*b.i;return com((a.r*b.r+a.i*b.i)/c,(a.i*b.r-a.r*b.i)/c);}
bool operator < (com a,com b){return a.r<b.r&&a.i<b.i;}
bool operator == (com a,com b){return fabs(a.r-b.r)<eps&&fabs(a.i-b.i)<eps;}
com sqrt(com a){
    if (fabs(a.i)<=eps) if (a.r>0) return com(sqrt(a.r),0);else return com(0,sqrt(-a.r));
    com b;
    b.i=sqrt((sqrt(a.r*a.r+a.i*a.i)-a.r)/2);
    b.r=a.i/2/b.i;
    return b;
}
struct jie{com x1,x2;jie(com _x1=0,com _x2=0):x1(_x1),x2(_x2){};};
inline jie work(com a,com b,com c){
    com det=sqrt(b*b-4*a*c);
    return jie((det-b)/com(2,0)/a,(0-det-b)/com(2,0)/a);
}
int main(){
}
View Code

 

posted @ 2017-08-18 14:16  swm_sxt  阅读(209)  评论(0编辑  收藏  举报