题意
给定一个n*m的原矩阵a,要求构造一个矩阵b满足
- 每一位bij都是aij的倍数
- bij <= 1e6
- bij与相邻元素之差为k4 (k>=1)
分析
因为所有的aij都是小于16的,因此完全可以构造一个数满足他是所有aij的倍数
用lcm从1处理到16,最后的值也只有720720,满足第二个条件,这样处理完之后,第一个和第二个条件都已经满足了,先用lcm填满整个bij
最后考虑第三个差值条件,既要满足倍数关系不能变,又要和周围的值构造出差,只能把自己的值加上当前aij4 ,记住要满足全部隔开,不能有一个相邻的值相等,因此用行和列的奇偶性去判断
code
#include <bits/stdc++.h>
using namespace std;
//#define ACM_LOCAL
#define fi first
#define se second
#define il inline
#define re register
const int N = 5e5 + 10;
const int M = 5e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-5;
const int MOD = 10007;
typedef long long ll;
typedef pair<int, int> PII;
typedef unsigned long long ull;
int a[505][505];
void solve() {
int ans = 1;
for (int i = 1; i <= 16; i++) {
ans = ans * i / __gcd(i, ans);
}
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
if ((i + j) & 1) cout << ans << " ";
else cout << ans + a[i][j] * a[i][j] * a[i][j] * a[i][j] << " ";
}
cout << endl;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
solve();
}