Other templates included QAQ

Here mainly included that do not know how classification template QAQ

 Ah I was too weak to actually have included template 

1. Fast power matrix

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 using namespace std;
 7 struct matrix
 8 {
 9     long long m[3][3];
10 }ans ,base;
11 long long n;
12 const long long mod=1000000007;
13 matrix muti(matrix a,matrix b)//Matrix multiplication satisfying distribution ratio (A + B) * C = A * C + B * C, is associative (A * B) * C = A * (B * C), but not commutative A * B! = B * A 
14  {
 15      Matrix tmp;
 16      for ( int I = . 1 ; I <= 2 ; I ++ )
 . 17       for ( int J = . 1 ; J <= 2 ; J ++ )
 18 is       {
 . 19           tmp.m [I] [J ] = 0 ;
 20 is           for ( int K = . 1 ; K <= 2 ; K ++ )
 21 is            tmp.m [I] [J] = (tmp.m [I] [J] + [I] AM [K] * BM [K] [J])% MOD;
 22 is      }
23      return tmp;
24 }
25 void qpow(long long x)
26 {
27     while(x)
28     {
29         if(x&1) ans=muti(ans,base);
30         base=muti(base,base);
31         x>>=1;
32     }
33 }
34 int main()
35 {
36     scanf("%lld",&n);
37     if(n<=2)
38     {
39         printf("%d",1);
40         return 0;
41     }
42     base.m[1][1]=1;base.m[1][2]=1;
43     base.m[2][1]=1;base.m[2][2]=0;
44     ans.m[1][1]=1;ans.m[1][2]=1;
45     qpow(n-2);
46     printf("%lld",ans.m[1][1]%mod);
47     return 0;
48  } 
Fast power matrix

 

2. discretization

1  // discrete templates 
2   int A [], B [] // original array, the discrete array 
. 3   for ( int I = 1 ; I <= n-; I ++ )
 . 4  {
 . 5       Scanf ( " % D " , & A [I]);
 . 6       B [I] = A [I];
 . 7  }
 . 8   Sort (A + . 1 , A + . 1 + n-);
 . 9   int len = UNIQUE (A + . 1 , A + . 1 + n-) and -A- . 1 ; // UNIQUE deduplication and returns the length 
10   for (int i=1;i<=n;i++)
11  {
12      b[i]=lower_bound(a+1,a+1+len,b[i])-a;
13  }
14  
15  
16  
17  int a[],int b[];
18  for(int i-1;i<=n;i++)
19  {
20      scanf("%d",&a[i]);
21      b[i]=a[i];
22  }
23  sort(a+1,a+1+n);
24  int len=unique(a+1,a+1+n)-a-1;
25  for(int i=1;i<=n;i++)
26  {
27      b[i]=lower_bound(a+1,a+1+len,b[i])-a;
28  }
Discretization

 

3. Fast Read

. 1  // int read fast type, etc. may be modified as long long 
 2  // if there is a lot of useless spaces Scanf 
 . 3  @ Reading only negative integer 
. 4 inline int Read ()
 . 5  {
 . 6      int RET = 0 , F = . 1 ; char CH = getchar ();
 . 7      the while (CH < ' 0 ' || CH> ' . 9 ' ) { IF (CH == ' - ' ) F = -f; CH = getchar ();}
 . 8      the while (CH> = ' 0 ' && CH <='9'){ret=ret*10+ch-'0';ch=getchar();}
 9     return ret*f;
10 }
11 
12 int n=read();
13 
14 inline int read()
15 {
16     int ret=0,f=1; char ch=getchar()
17     while(ch<'0'||ch>'9'){if(ch=='- ' ) F = -f; CH = getchar ();}
 18 is      the while (CH> = ' 0 ' && = CH < ' . 9 ' ) = {RET RET * 10 + CH-, ' 0 ' ; CH = getchar (); }
 . 19      return RET * F;
 20 is  }
 21 is  
22 is  
23 is  // apply a template class, consisting of different types of positive and negative reading an integer of 
24 template < class T>
 25  inline T read () {
 26 is      char C = getchar (); T X = 0 ; BOOL F = 0 ;
 27     while(!isdigit(c))f^=!(c^45),c=getchar();
28     while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
29     if(f)x=-x;return x;
30 }
31 int x=read<int>();
32 long long y=read<long long>();
qread

 

Guess you like

Origin www.cnblogs.com/xwx2354672579/p/11414388.html