zoukankan      html  css  js  c++  java
  • CF1438C Engineer Artem

    原题链接

    • 题意:给出 (n imes m) 的矩阵,然后构造出一个矩阵,在原矩阵上能给某个数加 (1) 或者不加,要求矩阵里所有元素相邻的不相同。
    • 题解:都说是很显然的套路,然而我并不知道,奇数和偶数不相等,所以,让每个斜对角线都是奇偶奇偶这样就可以,然后奇数+1就是偶数。
    • 代码:
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 1e6 + 10;
    int mp[111][111];
    int n, m;
    void solve() {
        cin >> n >> m;
        for (int i = 1; i <= n; i ++) 
            for (int j = 1; j <= m; j ++) 
                cin >> mp[i][j];
        for (int i = 1; i <= n; i ++) {
            for (int j = 1; j <= m; j ++) {
                int sum = i + j;
                if (sum % 2 == 0) {
                    if (mp[i][j]%2 == 0)continue;
                    else mp[i][j]++;
                } else {
                    if (mp[i][j]%2)continue;
                    mp[i][j]++;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cout << mp[i][j]<<" ";
            }cout << endl;
        }
    }
    int main() {
        int t = 1;cin >> t;
        while (t--) solve();
        return 0;
    }
    
  • 相关阅读:
    HDU 5135(再思考)
    HDU 5105
    HDU 5135
    Codeforces 985E
    Codeforces 985D
    Codeforces 975D
    Codeforces 975C
    Codeforces 976D
    HDU 1024 Max Sum Plus Plus (DP,水题)
    HDU 1003 Max Sum(DP,水题)
  • 原文地址:https://www.cnblogs.com/Xiao-yan/p/14743761.html
Copyright © 2011-2022 走看看