#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug “output for debug\n“#define pi (acos(-1.0))#define eps (1e-6)#define inf (1<<28)#define sqr(x) (x) * (x)#define mod 1000000007using namespace std;typedef long long ll;typedef unsigned long long ULL;//结构体构造分数struct node{ char sig;//正负号 long long molden;//分子分母};//最大公约数long long gcd(long long mlong long n){ return (m==0)?n:gcd(n%m m);}//重载运算符+node operator +(node anode b){ long long temp; int fa=0fb=0; node tp; fa=(a.sig==‘+‘)?1:-1; fb=(b.sig==‘+‘)?1:-1; tp.mol=fa*a.mol*b.den+fb*a.den*b.mol; tp.den=a.den*b.den; tp.sig=(tp.mol<0)?‘-‘:‘+‘; tp.mol=abs(tp.mol); temp=gcd(tp.moltp.den); tp.mol/=temp; tp.den/=temp; return tp;}//重载运算符-node operator -(node anode b){ long long temp; int fa=0fb=0; node tp; fa=(a.sig==‘+‘)?1:-1; fb=(b.sig==‘+‘)?1:-1; tp.mol=fa*a.mol*b.den-fb*a.den*b.mol; tp.den=a.den*b.den; tp.sig=(tp.mol<0)?‘-‘:‘+‘; tp.mol=abs(tp.mol); temp=gcd(tp.moltp.den); tp.mol/=temp; tp.den/=temp; return tp;}//重载运算符*node operator *(node anode b){ long long temp; int fa=0fb=0; node tp; fa=(a.sig==‘+‘)?1:-1; fb=(b.sig==‘+‘)?1:-1; tp.mol=fa*a.mol*fb*b.mol; tp.den=a.den*b.den; tp.sig=(tp.mol<0)?‘-‘:‘+‘; tp.mol=abs(tp.mol); temp=gcd(tp.moltp.den); tp.mol/=temp; tp.den/=temp; return tp;}//重载运算符/node operator /(node anode b){ long long temp; int fa=0fb=0; node tp; fa=(a.sig==‘+‘)?1:-1; fb=(b.sig==‘+‘)?1:-1; tp.mol=fa*a.mol*fb*b.den; tp.den=a.den*b.mol; tp.sig=(tp.mol<0)?‘-‘:‘+‘; tp.mol=abs(tp.mol); temp=gcd(tp.moltp.den); tp.mol/=temp; tp.den/=temp; return tp;}//高斯列主元消去法void Gausselimpiv(int niint njnode a[][20]){ int ijkmaxi; node temp; for(k=1; k { temp=a[k-1][k-1]; maxi=k-1; for(i=k-1; i { long long num=0ll; num=temp.mol*a[i][k-1].den-temp.den*a[i][k-1].mol; if(num<0) { temp=a[i][k-1]; maxi=i; } } printf(“第%d次消元\n主元元素:“k); //printf(“a[%2d][%2d]=%c%5lld/%-5lld “maxik-1a[maxi][k-1].siga[maxi][k-1].mola[maxi][k-1].den); //printf(“≈%c%-lf\n“a[maxi][k-1].siga[maxi][k-1].mol*1.0/a[maxi][k-1].den); printf(“a[%d][%d]=%c%lld/%lld “maxik-1a[maxi][k-1].siga[maxi][k-1].mol
共有 条评论
评论
共有 条评论