17.10.05
Posted *ZJ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了17.10.05相关的知识,希望对你有一定的参考价值。
- 上午
- 模拟考试
- Prob.1(AC)一道简单的博弈题,找到必胜态,反推普遍情况是否可以达到必胜态即可。
- Prob.2(AC)做到原题了呢。入门OJ 2092: [Noip模拟题]舞会
- Prob.3(WA了3个点)一道高精度的dp题,为减少状态,我把数据按某一权值分为了两类,对于一类反着dp,状态很少,只用到高精度加法。对于另一类(30分),要用到高精度乘法,然后进位时少打了一个+号,然后就没有然后了……
- 然后整理了三个模板,贴上!
//maybe have no mistakes,^_^ //1.Big_Int //only support + , * , = , < , <= , > , >= between Big_Int and Big_Int as well as Big_Int and int #define MAXN 1000 struct Big_Int{ int len,a[30]; Big_Int(){len=1; memset(a,0,sizeof(a));} void operator =(int val){ len=0; do{ a[++len]=val%MAXN; val/=MAXN; }while(val); } Big_Int operator +(const Big_Int &rtm) const{ Big_Int now; int l=max(len,rtm.len); for(int i=1;i<=l;i++){ now.a[i]+=a[i]+rtm.a[i]; now.a[i+1]=now.a[i]/MAXN; now.a[i]%=MAXN; } if(now.a[l+1]) l++; now.len=l; return now; } Big_Int operator +(const int &val) const{ Big_Int now,rtm; rtm=val; now=(*this)+rtm; return now; } Big_Int operator *(const Big_Int &rtm) const{ Big_Int now; int l=len+rtm.len; for(int i=1;i<=len;i++) for(int j=1;j<=rtm.len;j++){ now.a[i+j-1]+=a[i]*rtm.a[j]; now.a[i+j]+=now.a[i+j-1]/MAXN; now.a[i+j-1]%=MAXN; } while(!now.a[l]) l--; now.len=l; return now; } Big_Int operator *(const int &val) const { Big_Int now,rtm; rtm=val; now=(*this)*rtm; return now; } bool operator ==(const Big_Int & rtm) const{ if(len!=rtm.len) return 0; for(int i=len;i>=1;i--) if(a[i]!=rtm.a[i]) return 0; return 1; } bool operator <(const Big_Int &rtm) const{ if(len!=rtm.len) return len<rtm.len; for(int i=len;i>=1;i--) if(a[i]!=rtm.a[i]) return a[i]<rtm.a[i]; return 0; } bool operator >(const Big_Int &rtm) const{ return rtm<(*this); } bool operator <=(const Big_Int &rtm) const{ return (*this)<rtm||(*this)==rtm; } bool operator >=(const Big_Int &rtm) const{ return (*this)>rtm||(*this)==rtm; } bool operator ==(const int &val) const{ Big_Int rtm; rtm=val; return (*this)==rtm; } bool operator <(const int &val) const{ Big_Int rtm; rtm=val; return (*this)<rtm; } bool operator >(const int &val) const{ Big_Int rtm; rtm=val; return (*this)<rtm; } bool operator <=(const int &val) const{ Big_Int rtm; rtm=val; return (*this)<=rtm; } bool operator >=(const int &val) const{ Big_Int rtm; rtm=val; return (*this)>=rtm; } void print(){ printf("%d",a[len]); for(int i=len-1;i>=1;i--){ printf("%03d",a[i]); } } }; //2.Fraction //only support + , * and reduction for fraction struct Fraction{ ll Numerator,Denominator; ll Gcd(ll a,ll b){ while(a^=b^=a^=b%=a); return b; } bool Zero(){ return Numerator==0; } void Clear(){ Numerator=Denominator=0; } void Reduction(){ ll g=Gcd(Numerator,Denominator); Numerator/=g; Denominator/=g; } Fraction operator +(Fraction &rtm){ Fraction New; if(!Numerator&&!Denominator) New.Numerator=rtm.Numerator,New.Denominator=rtm.Denominator; else{ ll g=Gcd(Denominator,rtm.Denominator); ll a=Denominator/g,b=rtm.Denominator/g; New.Denominator=a*b*g; New.Numerator=Numerator*b+rtm.Numerator*a; } New.Reduction(); return New; } Fraction operator *(Fraction &rtm){ Fraction New; New.Denominator=Denominator*rtm.Denominator; New.Numerator=Numerator*rtm.Numerator; New.Reduction(); return New; } void Read(){ cin>>Numerator; Denominator=1; } void Write(){ cout<<Numerator; if(Denominator!=1&&Denominator!=0) cout<<"/"<<Denominator<<endl; } } //3.Maxtrix //noly supprt * , ^(quick pow) for Maxtrix struct Maxtrix{ int r,c; int val[75][75]; Maxtrix(){ r=c=0; memset(val,0,sizeof(val)); } void identity(int l){ r=c=l; for(int i=1;i<=l;i++) val[i][i]=1; } Maxtrix operator * (Maxtrix const b){ // c==b.r Maxtrix now; now.r=r; now.c=b.c; for(int i=1;i<=r;i++) for(int j=1;j<=b.c;j++) for(int k=1;k<=c;k++) now.val[i][j]=(now.val[i][j]+val[i][k]*b.val[k][j])%mod; return now; } Maxtrix operator ^ (int b){ Maxtrix base,now; base=*this; now.identity(this->r); while(b){ if(b&1) now=now*base; base=base*base; b>>=1; } return now; } } //____________________________________________________________________by *ZJ
- 下午
- 晚上
- 回家了,hahaha
- End
- 2天半的休息来了
以上是关于17.10.05的主要内容,如果未能解决你的问题,请参考以下文章