- 说明:这篇博文将不定期更新,我会把最近所学到的技巧贴在这里。
- 快速输入输出:
inline int in(){
int W=1,X=0;
char Ch=0;
while(!isdigit(Ch)){
if(Ch=='-') W=-1;
Ch=getchar();
}
while(isdigit(Ch))
X=(X<<3)+(X<<1)+(Ch^'0'),Ch=getchar();
return X*W;
}
inline void out(int X,char *S){
if(X<0) putchar('-'),X=-X;
if(X>9) out(X/10,"");
putchar(X%10+'0');
printf(S);
}
值得注意的是,这两个函数需要include<cctype>
当然,bits依然万能!
- 矩阵乘法:
网上搜了一堆,没看懂,最后发现还是书本最靠谱,其实核心就一个式子(原文照抄):
然后愉快的把它写进了结构体,挺方便的:
#include<bits/stdc++.h>
#define Rep(a,b,c) for(register int (a)=(b);(a)<=(c);(a)++)
using namespace std;
inline int in(){
int W=1,X=0;
char Ch=0;
while(!isdigit(Ch)){
if(Ch=='-') W=-1;
Ch=getchar();
}
while(isdigit(Ch))
X=(X<<3)+(X<<1)+(Ch^'0'),Ch=getchar();
return X*W;
}
inline void out(int X,char *S){
if(X<0) putchar('-'),X=-X;
if(X>9) out(X/10,"");
putchar(X%10+'0');
printf(S);
}
struct Matrix{
int a[11][11],m,n;
Matrix& operator*(Matrix& b){
Matrix c;
c.m=m,c.n=b.n;
Rep(i,1,m)
Rep(j,1,b.n){
c.a[i][j]=0;
Rep(k,1,n)
c.a[i][j]+=a[i][k]*b.a[k][j];
}
return c;
}
inline void init(int x,int y){
m=x,n=y;
Rep(i,1,m)
Rep(j,1,n)
a[i][j]=in();
}
inline void outit(){
out(m," "),out(n,"\n");
Rep(i,1,m){
Rep(j,1,n)
out(a[i][j]," ");
puts("");
}
}
}A,B,C;
int main(){
int m,n,p;
m=in(),n=in(),p=in();
A.init(m,n),B.init(n,p);
C=A*B;
C.outit();
return 0;
}