1641: 【例 1】矩阵 A×B
sol:矩阵乘法模板。三个for循环
#includeusing namespace std;typedef long long ll;inline ll read(){ ll s=0; bool f=0; char ch=' '; while(!isdigit(ch)) { f|=(ch=='-'); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s);}#define R(x) x=read()inline void write(ll x){ if(x<0) { putchar('-'); x=-x; } if(x<10) { putchar(x+'0'); return; } write(x/10); putchar((x%10)+'0'); return;}#define W(x) write(x),putchar(' ')#define Wl(x) write(x),putchar('\n')const int N=105;int n,m,p,a[N][N],b[N][N],c[N][N];int main(){ int i,j,k; R(n); R(m); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) R(a[i][j]); } R(p); for(i=1;i<=m;i++) { for(j=1;j<=p;j++) R(b[i][j]); } for(i=1;i<=n;i++) { for(j=1;j<=p;j++) { for(k=1;k<=m;k++) c[i][j]+=a[i][k]*b[k][j]; } } for(i=1;i<=n;i++,putchar('\n')) { for(j=1;j<=p;j++) W(c[i][j]); } return 0;}/*input2 31 2 33 2 121 12 23 3output14 1410 10*/