HDU 4920 (水~)
2019-04-14 20:23发布
生成海报
题意: 求两个矩阵的模3乘积。
被我用暴力炸过去了。因为模3, 所以0会出现的比较多, 所以枚举的时候0可以省去一维。
using namespace std;
int n;
int a[maxn][maxn], b[maxn][maxn];
int ans[maxn][maxn];
int main () {
while (scanf ("%d", &n) == 1) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf ("%d", &a[i][j]);
a[i][j] %= 3;
ans[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf ("%d", &b[i][j]);
b[i][j] %= 3;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) if (a[i][j]) {
for (int k = 1; k <= n; k++) {
ans[i][k] += a[i][j]*b[j][k];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
printf ("%d%c", ans[i][j]%3, (j == n ? '
' : ' '));
}
}
}
return 0;
}
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮