1. 程式人生 > >17.10.05

17.10.05

cti bar rip 模擬題 link toolbar class false operator

  • 上午
    • 模擬考試
      • 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