Codeforces Round #701 (Div. 2) D. Multiples and Power Differences 构造lcm

题意

给定一个n*m的原矩阵a,要求构造一个矩阵b满足

  1. 每一位bij都是aij的倍数
  2. bij <= 1e6
  3. 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();
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值